Python Virtual Environments
Last updated 2026-08-20 · 3 notes · 3 tags
Tags: python venv packages
A virtual environment (“venv”) is a private folder of Python packages for one project. That way Project A and Project B can use different package versions without breaking each other.
Note: Create the venv inside the project folder. Activate it whenever you work on that project.
Create
From your project folder:
cd ~/projects/your-project
python3 -m venv venv
Activate (Linux / WSL / macOS)
source venv/bin/activate
Your prompt usually shows (venv) when it is active.
Deactivate
deactivate
Install a package
With the venv active:
pip install package-name
Save and reinstall requirements
pip freeze > requirements.txt
pip install -r requirements.txt
Note: Commit
requirements.txtto Git so another machine can recreate the same packages. Do not commit the wholevenv/folder (addvenv/to.gitignore).
Why not install everything globally?
Global installs clutter your system Python and make “it works on my machine” problems more likely.
Note: CLI tools you want available everywhere are a better fit for
pipx(see WSL on Windows or Native Linux). Libraries for a project belong in that project’s venv.
Common mistakes
- If
pip installseems to hit the wrong Python, check that the venv is activated. - Each new terminal starts deactivated — run
source venv/bin/activateagain. - These commands are for Linux / WSL Bash. Windows PowerShell uses a different activate script.
This project captures ideas, decisions, and lessons I’ve learned while building with AI. It aims to help non-technical users understand and use these tools effectively. I also use AI at times to improve or refine the content.
Readers should use the commands and instructions here with care. The creator accepts no responsibility for system damage, data loss or other consequences resulting from their use.