Why venv Matters
Different projects need different library versions. Installing everything globally eventually breaks something. A virtual environment gives each project its own isolated packages.
Creating One
python -m venv .venv
Activating
# macOS / Linux source .venv/bin/activate # Windows PowerShell .venv\Scripts\Activate.ps1
Installing Packages
pip install requests numpy pip freeze > requirements.txt
Deactivating
deactivate
Best Practices
- Always add
.venv/to.gitignore. - Commit
requirements.txt, not the venv itself. - One venv per project.
Practise this on PyForm โ free
PyForm runs Python in your browser with an AI tutor trained for HKDSE. No install, no credit card.
Open PyForm โ