Part 16 / Topic 3 of 6
Editable installs: pip install -e .
A normal pip install . copies your package's files into the venv's site-packages. Change your source code afterwards, and the installed copy does not change — you would have to reinstall every time, which gets old fast while you are actively developing.
An editable install (-e, for editable) installs a link back to your source folder instead of a copy. The package becomes importable everywhere, exactly like a normal install (so rupee-split works as a command, and import rupee_split works from any script) — but every edit to the source takes effect immediately, with no reinstall.
$ cd rupee-split # the project with src/rupee_split/ and pyproject.toml
$ python -m venv .venv && source .venv/bin/activate
(.venv) $ pip install -e .
(.venv) $ rupee-split 900 --people 3
Friend 1: pay ₹300
Friend 2: pay ₹300
Friend 3: pay ₹300
Total collected: ₹900
Verified end to end (a throwaway venv, editing the installed package's source and re-running with no reinstall step):
(.venv) $ pip show rupee-split
Name: rupee-split
Version: 0.1.0
Location: .../site-packages
Editable project location: /path/to/rupee-split <- a LINK, not a copy
(trimmed to the interesting fields; pip show also prints Summary, Author, Requires, etc.)
After changing one line in src/rupee_split/cli.py (the ₹ sign to Rs, then back), running rupee-split again picked up the change immediately — no pip install was run in between. That is the entire point of -e.
| Install | Copies your code? | Edits take effect | Use it for |
|---|---|---|---|
pip install . |
Yes | only after reinstalling | shipping to someone else, or a final check before release |
pip install -e . |
No (a link) | immediately | working on your own package day to day |
pip install some-package |
Yes | never (it's not yours) | using someone else's package |
🔍 Going deeper: editable installs used to drop a
.egg-linkfile and editeasy-install.pth; modernsetuptools/hatchlinginstead write a small.pthfile or a tiny "finder" that points straight at yoursrc/folder — same idea, cleaner mechanism (PEP 660). You never need to look at these files;pip install -e .andpip uninstallmanage them for you.
Exercise 3: A src-layout project checker
Scenario: A team keeps breaking their packages by forgetting __init__.py or a tests/ folder. Build a checker that catches this before it ships.
What to do:
- Write
check_layout(package, files): given a package name and asetof file paths a project has, return the list of required paths that are missing. Required paths arepyproject.toml,src/<package>/__init__.py(with underscores, even if the project name uses hyphens) andtests/. - Loop over
PROJECTSbelow. For each one, turn its name into a package name (hyphens to underscores) and callcheck_layout. Print<name>: valid src layoutif nothing is missing, otherwise<name>: INVALID, missing <list>.
Starting data:
PROJECTS = {
"good-project": {
"pyproject.toml", "src/good_project/__init__.py",
"src/good_project/cli.py", "tests/",
},
"missing-init": {
"pyproject.toml", "src/missing_init/cli.py", "tests/",
},
"flat-layout": {
"pyproject.toml", "missing_init.py",
},
}
Sample output:
good-project: valid src layout
missing-init: INVALID, missing ['src/missing_init/__init__.py']
flat-layout: INVALID, missing ['src/flat_layout/__init__.py', 'tests/']
💡 Hint: Build the required list with an f-string or "src/{package}/__init__.py".format(package=package), then keep only the ones not in files, in the same order you listed them.
Show the solution to Exercise 3
"""Exercise 3: A src-layout project checker.
Run: python ex03.py (macOS/Linux: python3 ex03.py)
"""
REQUIRED = [
"pyproject.toml",
"src/{package}/__init__.py",
"tests/",
]
PROJECTS = {
"good-project": {
"pyproject.toml",
"src/good_project/__init__.py",
"src/good_project/cli.py",
"tests/",
},
"missing-init": {
"pyproject.toml",
"src/missing_init/cli.py",
"tests/",
},
"flat-layout": {
"pyproject.toml",
"missing_init.py",
},
}
def check_layout(package: str, files: set[str]) -> list[str]:
"""Return the list of required paths that are missing."""
required = [path.format(package=package.replace("-", "_")) for path in REQUIRED]
return [path for path in required if path not in files]
def main() -> None:
for name, files in PROJECTS.items():
package = name.replace("-", "_")
missing = check_layout(package, files)
if missing:
print(f"{name}: INVALID, missing {missing}")
else:
print(f"{name}: valid src layout")
if __name__ == "__main__":
main()