pythonuv

How to import nested modules with uv


I am managing a project with uv. My project includes

- src
  - app.py
  - constants.py
- notebooks
  - testing.ipynb
- pyproject.toml

where my pyproject.toml is

[project]
name = "benchmark-extractor"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
    "anthropic>=0.42.0",
    "ipykernel>=6.29.5",
    "markitdown>=0.0.1a3",
    "pandera>=0.22.1",
    "tabula-py>=2.10.0",
]

I want to import app.py and constants.py into notebooks/testing.ipynb, for experimentation purposes. When I do this naively, e.g. import src.app, I get a ModuleNotFoundError.

I believe I could approach this using uv pip install -e . (e.g. Sibling package imports) but when I try that, I get ERROR: Package 'benchmark-extractor' requires a different Python: 3.11.3 not in '>=3.13'.


Solution

  • Add this section into pyproject.toml:

    [tool.uv]
    package = true
    

    Then run uv sync

    Now you should be able to import app in notebooks/testing

    https://docs.astral.sh/uv/concepts/projects/config/#project-packaging