[Python] How to install a local package with UV?

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I’m working on a Python project using uv as my package manager and struggling with ModuleNotFoundError when importing local packages. My goal is to make config/ and packages/src/ available throughout the project (e.g., from config.connection_config import database_config) after an editable install with uv pip install -e ..

    Here’s my project structure:

    dashboard/
    ├── config/
    │ ├── __init__.py
    │ └── connection_config.py
    │ └── env/
    ├── packages/
    │ └── src/
    │ └── (other packages/modules with __init__.py)
    ├── services/
    │ └── data_ingestion/
    │ └── ingest_data.py
    ├── pyproject.toml
    └── .venv/


    And my pyproject.toml:

    [project]
    name = "dashboard"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.12"
    dependencies = [
    "loguru>=0.7.3",
    "mysql-connector>=2.2.9",
    "pandas>=2.2.3",
    "paramiko>=3.5.1",
    "polars>=1.23.0",
    "pydantic-settings>=2.8.0",
    "streamlit>=1.41.1",
    ]

    [project.optional-dependencies]
    test = ["pytest>=8.3.5"]

    [tool.setuptools.packages.find]
    where = ["packages/src", "config"] # Search in both directories
    include = ["*"] # Include all packages found
    exclude = ["tests*"] # Exclude test directories

    [tool.pytest.ini_options]
    pythonpath = "."


    I run uv pip install -e . from the root (dashboard/), expecting config and packages/src to be importable anywhere in the project. However, when running python services/data_ingestion/ingest_data.py (which does from config.connection_config import database_config), I get:

    ModuleNotFoundError: No module named 'config'


    I suspect I’m misconfiguring pyproject.toml or misunderstanding how uv and setuptools handle editable installs. Things I’ve tried:

    Running uv pip install -e . from the root. Verifying init.py exists in config/. Running the script from different directories (root and services/data_ingestion/), same error. How should I configure pyproject.toml to make config/ and packages/src/ importable project-wide? Are there best practices for structuring and running such a project with uv, I would really like to undersdtand this better? Any help is appreciated!

    Continue reading...

Compartilhe esta Página