r/learnpython • u/spedgenius • 1d ago
Editable module not found error
I have a custom module that I am developing and I can not get it to import when installing with
"uv pip install -e ."directory structure:
niceachemy/
|-src/
| |-nicealchemy/
| | |-__init__.py
| | |-fields.py
|-pyproject.toml
|-setup.pypyproject.toml:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "nicealchemy"
version = "0.1"setup.py:
from setuptools import setup, find_packages
setup(name='nice-alchemy',
version='0.1',
author='Nathan Shaffer',
author_email='nathanjshaffer@gmail.com',
license='MIT',
packages=find_packages(where='src'),
package_dir={
'nicealchemy': 'src/nicealchemy',
},
zip_safe=False)script is running on a nicegui docker image that uses uv by default.
When I install my module from github, it works just fine, but if I try to install from a volume as editable, import fails with
ModuleNotFoundError: No module named 'nicealchemy'I have tried specifying the .venv location to pip install and editable compatibility mode
uv pip install --python /opt/venv/bin/python -e . --config-setting editable_mode=compatI have listed the installed modules from within the script and it correctly lists my module:
from importlib.metadata import distributions
installed = sorted(
f"{dist.metadata['Name']}=={dist.version}"
for dist in distributions()
)
for pkg in installed:
print(pkg)/opt/venv/lib64/python3.14 shows a dist-info directory for the module.
I have rebuilt the docker stack many times to make sure the pip install is not being shadowed by the git module installation.
I just can not figure out what I else could possibly check for at this point
EDIT: So what I ended up doing, as nothing I tried doing would work, is I just made a simling in /opt/venv/lib64/python3.14/site-packages to the module src directory, and that worked. I know its not the correct way, but honestly, not sure why the editable install doesn't just do that.
2
u/EszterSantos72 1d ago
In setup.py, set package_dir={"": "src"} and ensure packages=find_packages(where="src") so that Python correctly locates your nicealchemy module inside the src directory during editable installs.
1
u/AdhesivenessFew8441 1d ago
Two things I would check. First, your package_dir mapping does not match the src layout. With find_packages(where='src') the usual setting is package_dir={'': 'src'}, and the custom mapping you have tends to confuse the editable finder even when a normal install works. Second, an editable install writes the absolute path of your project into a .pth file (or an editable finder) inside site-packages, so the path that existed when you ran uv pip install has to exist at that same path when the script runs. If the install happens during the image build and the volume is only mounted at runtime, or is mounted somewhere else, the dist-info is there but the import has nowhere to go. Look inside /opt/venv/lib64/python3.14/site-packages for the .pth file, open it, and confirm that the path in it exists inside the running container.
1
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 23h ago
If you're already using
uv,uv syncwhich automatically installs the project as editable (alongside any dependencies it might have)setup.pyas all the metadata should be inpyproject.tomlFor example, here I would use
and then remove
setup.pyentirely.