How to isolate Python projects and manage external libraries
Different Python projects often require different versions of packages. A virtual environment creates an isolated workspace so dependencies don’t conflict with each other or with system‑wide Python installations.
Use Python’s built‑in venv module:
python -m venv venv
Windows:
venv\Scripts\activate
macOS/Linux:
source venv/bin/activate
deactivate
Once the environment is active, use pip to install packages:
pip install requests
pip install flask
pip list
Save all installed packages to a file:
pip freeze > requirements.txt
Recreate the same environment elsewhere:
pip install -r requirements.txt
pip install --upgrade requests
pip uninstall flask
pipx installs Python tools globally but isolates them in their own environments:
pip install pipx
pipx install black
requirements.txt to version control.pip freeze to keep dependencies reproducible.Now that you can manage environments and dependencies, you're ready to explore how to work with external libraries in Lesson 15: Working with External Libraries (pip).
← Back to Lesson Index