[Python] error: package directory 'mypackage' does not exist using pyproject.toml

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    Problem


    Whilst running some unit tests I was presented with the following error when trying to import from absolute path:

    tests/unit/test_parameter_combinations.py:3: in <module>
    from TradingPlatform.core.parameter_combinations import ParameterCombinations
    E ModuleNotFoundError: No module named 'TradingPlatform'


    ChatGPT suggested that if I wanted to package this, it might be useful to create an editable install and this could resolve the path issue. I also wanted to ship this in the future. I created the following toml file:

    [build-system]
    requires = ["setuptools>=64", "wheel"]
    build-backend = "setuptools.build_meta"

    [project]
    name = "TradingPlatform"
    version = "0.1.0"
    description = "A platform for trading infrastructure and strategy testing."
    dependencies = [
    "pandas",
    "numpy",
    "scikit-learn",
    "statsmodels",
    ]

    [tool.setuptools]
    packages = ["TradingPlatform"]

    [tools.setuptools.packages.find]
    where = ["."]
    include = ["TradingPlatform*"]


    This is a simplified project tree (I have removed some of the modules in core and tests to make this smaller).

    TradingPlatform
    ├── __init__.py
    ├── core
    │ ├── __init__.py
    │ ├── base_trading_strategy.py
    ├── notebooks
    │ └── main.ipynb
    ├── pyproject.toml
    ├── tests
    │ ├── integration
    │ │ └── __init__.py
    │ └── unit
    │ ├── __init__.py
    │ └── test_strategy_performance_evaluation.py
    └── utils
    ├── __init__.py
    ├── helper_funcs.py
    └── logging_setup.py


    This has led to the following error error: package directory 'TradingPlatform' does not exist.

    What I Have Tried


    I have been stuck on this error for quite some time, having tried reconfiguring the toml file, uninstalling and reinstalling the package but to no avail. Below are a few of the different toml file configurations I have tried:

    1.

    [tool.setuptools]
    packages = ["TradingPlatform", "TradingPlatform.core", "TradingPlatform.utils", "TradingPlatform.tests"]

    [tool.setuptools.package-dir]
    # Explicitly tell setuptools where to find the root package directory
    TradingPlatform = "TradingPlatform"


    [tool.setuptools]
    packages = ["TradingPlatform", "TradingPlatform.core", "TradingPlatform.utils", "TradingPlatform.tests"]


    [tool.setuptools.packages.find]
    where = ["."]


    I was expecting to find the directory name, TradingPlatform, and each of the modules

    core
    tests
    utils


    in the top_level.txt file within the .egg-info directory, but it is only populated with TradingPlatform and in some instances is empty.

    I am quite unfamiliar with shipping a package so would really appreciate any guidance in resolving this issue. Anything else I can provide for further detail, please let me know.

    Continue reading...

Compartilhe esta Página