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 content repository is based on the hands-on experience of Naveen Bachwani. AI tools were also used in augmenting and refining it. The goal is to help non-technical users get familiar with these tools, so they may be able to use them effectively.
Readers are responsible for using any commands or instructions provided here with appropriate caution. The creator of this site accepts no responsibility for system damage, data loss, or other consequences resulting from their use.