1.pip and venv
pip installs, upgrades, and removes Python packages. venv creates an isolated environment with its own pip and package directory, so installing something for one project never affects another.
Key features
- python -m venv .venv creates an isolated environment in the .venv directory
- Activating a venv puts its own python/pip first on PATH (.venv/bin or .venv\Scripts)
- pip install <package> installs into whichever environment is currently active
- pip list / pip freeze show what is installed in the active environment
- A venv is disposable — deleting and recreating it affects nothing outside it
pip — the commands worth knowing
- No venv active
- pip install targets the ONE global Python
- Every project on the machine shares it
- Two projects needing different versions collide
- .venv activated
- Its own python and pip, first on PATH
- Its own isolated site-packages directory
- Disposable — delete and recreate, affects nothing else
Command
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # macOS/Linux
pip install requestsvenv gives each project its own isolated Python and package set; pip installs into whichever environment is currently active.