pip install
- Python course
- Advanced
- Lesson 76/83
- 5 min
Learn development mode with pip install -e .
pip install -e .
The pip install -e . command installs the project in editable mode. The source directory is added to sys.path; code changes apply without reinstalling.
pip install -e .The -e flag is short for --editable. This mode is handy while developing the project; every change reflects immediately in the installed package.
Editable mode and sys.path
In editable mode pip writes a .pth file that puts the source directory at the front of sys.path. So import demo finds the code in the source directory directly.
import sys
print(sys.path[0]) # source directoryThis approach skips the build step, so it speeds up development. Before shipping to production it is a good habit to also test the normal install with pip install ..
Practice Add the source directory to sys.path
Start with import sys. Define src_dir = "/home/user/project". Add the source directory to the front of the path with sys.path.insert(0, src_dir). Print the added path with print(sys.path[0]).
Starter code
# bring in the sys module
# assign a source directory to src_dir
# insert src_dir at the front of sys.path
# print sys.path[0]Sample solution
import sys
src_dir = "/home/user/project"
sys.path.insert(0, src_dir)
print(sys.path[0])Expected output
/home/user/project
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Complete the pip install command
pip install ____ .
pip install -e .
Explanation: The -e flag enables editable mode.
2 What does -e do in pip install -e .?
- Creates a virtual environment
- Removes the package
- Enables editable mode Correct answer
- Builds a wheel
Explanation: -e enables editable mode; the source is added to sys.path.
3 Match the pip install concepts
| Term | Meaning |
|---|---|
-e |
Editable mode |
sys.path |
Import path |
.pth |
Path-adding file |
pip install . |
Normal install |