How do I support pip editable (-e) installs with pyproject.toml + setup.py (or setup.cfg)? #3821
-
I have an old Python project that I am trying to update to work on Python 3.10. In the process, I have swapped out my setup.py for a pyproject.toml, as that seems to be the recommended practice moving forward. Everything works except for editable installs: (i.e. The "Important" admonition box on this page and footnote [1] indicate that this might be a limitation of the current beta status, and that I can support editable installs by including either a simple setup.py, or setup.cfg, along with my pyproject.toml. Unfortunately, I haven't been able to make that work either.
How would I adapt my project (below) to support editable installs?
Other References: Minimal Example:
The project is organized with a flat-laout.
Virtual Environment: py -3.10 -m venv .venv
.venv\scripts\activate
(.venv) python -m pip install --upgrade pip
(.venv) pip install --upgrade setuptools
__init__.py foo = "bar" setup.py from setuptools import setup, find_packages
setup(
name="mypkg",
version="1.2.3",
packages=find_packages(
where=".",
include=["mypkg*"],
)
) Alternate setup.py (verbatim from setuptools documentation): from setuptools import setup
setup() pyproject.toml [build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "mypkg"
version = "1.2.3"
[tool.setuptools.packages.find]
where = ["."]
include = ["mypkg*"] Install / Test: (.venv) pip install --force-reinstall -e ./mypkg
(.venv) python -c "import mypkg;print(mypkg.foo)" Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: module 'mypkg' has no attribute 'foo' |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @fndrplayer39, I think what is happening here is that you are hitting a limitation of editable installations for flat-layouts, due to the where you are running your test commands from. This limitation is described in the docs:
If you change directory before running your test script, it should be fine: > docker run --rm -it python:3.10 /bin/bash
mkdir -p /tmp/mypkg/mypkg
cd /tmp/mypkg
python3.10 -m venv /tmp/.venv
cat <<EOF > pyproject.toml
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "mypkg"
version = "1.2.3"
[tool.setuptools.packages.find]
where = ["."]
include = ["mypkg*"]
EOF
echo 'foo = "bar"' > mypkg/__init__.py
/tmp/.venv/bin/python -m pip install -U pip
/tmp/.venv/bin/python -m pip install --force-reinstall -e .
cd /tmp/.venv
./bin/python -c "import mypkg;print(mypkg.foo)"
# => bar (Just a friendly reminder that for the Python interpreter any folder can be a namespace package, even if you don't install it: mkdir /tmp/folder
cd /tmp
python -c 'import folder; print(folder)'
# => <module 'folder' (<_frozen_importlib_external._NamespaceLoader object at 0x7ff834b19cf0>)> ) |
Beta Was this translation helpful? Give feedback.
-
You don't need a
So far, I recommend only using
|
Beta Was this translation helpful? Give feedback.
Hi @fndrplayer39, I think what is happening here is that you are hitting a limitation of editable installations for flat-layouts, due to the where you are running your test commands from. This limitation is described in the docs:
If you change directory before running your test script, it should be fine: