Editable Installs
While you develop a package you want two things at once: it should be installed (so imports, entry points and metadata work as they will for users) and live (so an edit to the source shows up without rebuilding a wheel). An editable install, pip install -e ., gives you both. Since PEP 660 it is a standard backend hook (build_editable), so it works the same way with every modern backend.
What gets installed
The backend builds a special wheel that contains the metadata and, instead of your code, a pointer to your source tree. Most backends use a .pth file: Python reads every *.pth file in site-packages at start-up and adds the paths in it to sys.path. This lesson uses setuptools; hatchling works the same way but needs the small editables helper package, which this course's offline index doesn't carry.
python3 -m venv .venv && . .venv/bin/activate
mkdir -p greet/src/greet && cd greet
cat > pyproject.toml <<'TOML'
[build-system]
requires = ["setuptools>=77"]
build-backend = "setuptools.build_meta"
[project]
name = "greet"
version = "0.1.0"
requires-python = ">=3.13"
[project.scripts]
greet = "greet:main"
TOML
cat > src/greet/__init__.py <<'PY'
def main():
print("Hello from the source tree")
PY
pip install -q -e .
echo "--- what landed in site-packages"
ls ../.venv/lib/python3.13/site-packages | grep -i greet
cat ../.venv/lib/python3.13/site-packages/__editable__.greet-0.1.0.pth; echo
python -c 'import greet; print(greet.__file__)'
pip show greet | grep -i location
greet
echo "--- edit the source: no reinstall needed"
sed -i 's/from the source tree/after an edit/' src/greet/__init__.py
greet--- what landed in site-packages
__editable__.greet-0.1.0.pth
greet-0.1.0.dist-info
/home/learner/greet/src
/home/learner/greet/src/greet/__init__.py
Location: /home/learner/.venv/lib/python3.13/site-packages
Editable project location: /home/learner/greet
Hello from the source tree
--- edit the source: no reinstall needed
Hello after an edit
import greet now resolves to src/greet/__init__.py directly, and pip show reports the Editable project location. The greet launcher was generated as usual from the entry point.
What still needs a reinstall
The live link covers code only. Anything that's stored in the installed metadata is a snapshot taken at install time:
| Change | Live? |
|---|---|
| editing an existing module | yes |
| adding a new module or subpackage inside the package | yes (it's under the linked directory) |
| adding/changing a dependency | no: reinstall so the resolver installs it |
| adding a console script or entry point | no: launchers and entry_points.txt are written at install |
| changing the version or other metadata | no: importlib.metadata.version() reads the installed METADATA |
| compiled extensions | no: rebuild them |
python3 -m venv .venv && . .venv/bin/activate
mkdir -p greet/src/greet && cd greet
printf '[build-system]\nrequires = ["setuptools>=77"]\nbuild-backend = "setuptools.build_meta"\n\n[project]\nname = "greet"\nversion = "0.1.0"\n\n[project.scripts]\ngreet = "greet:main"\n' > pyproject.toml
printf 'def main(): print("hello")\ndef bye(): print("bye")\n' > src/greet/__init__.py
pip install -q -e .
echo "--- add a script and bump the version in pyproject.toml"
sed -i 's/^version = "0.1.0"/version = "0.2.0"/' pyproject.toml
echo 'greet-bye = "greet:bye"' >> pyproject.toml
greet-bye 2>&1
python -c 'from importlib.metadata import version; print("installed metadata says", version("greet"))'
echo "--- reinstall picks both up"
pip install -q -e .
greet-bye
python -c 'from importlib.metadata import version; print("installed metadata says", version("greet"))'--- add a script and bump the version in pyproject.toml
/w/main.sh: line 9: greet-bye: command not found
installed metadata says 0.1.0
--- reinstall picks both up
bye
installed metadata says 0.2.0
Rule of thumb: after editing pyproject.toml, reinstall. With uv or Poetry you rarely notice, because uv sync/uv run and poetry install reinstall the project when its metadata changes.
Editable installs in project managers
You usually don't type pip install -e . in a managed project:
- uv:
uv syncanduv runinstall the project itself in editable mode (inuv.lockit appears assource = { editable = "." }).uv pip install -e .is the pip-style spelling. - Poetry:
poetry installinstalls the root project in editable mode ("Installing the current project: greet (0.1.0)");--no-rootskips it. - setuptools offers a strict mode (
pip install -e . --config-settings editable_mode=strict) that links individual files instead of the whole directory, so new files are not picked up, which mimics the wheel more closely.
Tip: Editable installs are for development only. CI should test the built wheel at least once (
pip install dist/*.whl, then run the tests), because an editable install happily imports files that the wheel forgot to include.
Test yourself
How does an editable install make import greet load your source tree?
- It copies the source into site-packages on every import
- A .pth file (or import hook) in site-packages adds the source directory to sys.path
- It symlinks site-packages to src
- It sets PYTHONPATH in activate
You added a new console script to pyproject.toml of an editable project. What do you need to do?
- Nothing
- Reinstall (pip install -e . / uv sync / poetry install) so the launcher and entry_points.txt are regenerated
- Restart the shell
- Delete __pycache__
Why should CI also test the built wheel, not only an editable install?
- Wheels run faster
- An editable install imports straight from the source tree, so files missing from the wheel go unnoticed
- Editable installs can't run tests
- pytest requires wheels