brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: python -m pip install -e makes code changes live without reinstalling

Python
~/tips/tip-python-pip-install-editable

.venv/bin/python -m pip install -e .

Install your own project so edits to the source take effect on the next run.

For a small tool with a pyproject.toml, I’d install it in editable mode in its venv. Then you can change the code and run the command straight away.

cd ~/projects/mytool
python3 -m venv .venv
.venv/bin/python -m pip install -e .
.venv/bin/mytool --help

A normal pip install . copies your package into site-packages, so every change needs another install. With -e (editable) pip only puts a pointer there that leads back to your source folder. Imports read your working copy, and the console scripts from [project.scripts] are created as usual.

It’s the setup I want while developing, because tests, the command line entry point and python -c 'import mytool' all see the same code without any PYTHONPATH tricks.

Not everything is live, though. Python code changes are, but if you change pyproject.toml, like adding a dependency or a new entry point, you need to run the install again. Compiled extensions need a rebuild too. And because the venv now depends on your source folder, moving or deleting that folder breaks the install, so don’t use editable installs for something you deploy.

Further reading: pip install –editable, Editable installs (pip docs)

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link