A virtual environment is a separate folder that holds the packages one Python project needs. Each project gets its own set, so updating one library for one project does not break another.
Why it matters
Two projects may need two different versions of the same library. Without an environment, one of them will eventually stop working.
Create and use one
- Create it:
python -m venv venv - Activate it on Windows:
venv\Scripts\activate - Activate it on Linux or macOS:
source venv/bin/activate - Install packages while it is active, then save them with
pip freeze > requirements.txt.
Keep it out of Git
Do not commit the venv folder. Add it to .gitignore, and share requirements.txt instead, so others can recreate the same setup.
Next step: see our Python Full Stack course at ScholarLogic, or book a free demo class. A counsellor will share the fee and the next batch dates.
