What is a Virtual Environment?
A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python environments for them. This means each project can have its own dependencies regardless of what dependencies every other project has.
Mac Commands
# Create virtual environment
python -m venv env
# Activate
source env/bin/activate
Windows Commands
# Create virtual environment
python -m venv env
# Activate
cd env
cd Scripts
activate
Useful Tips
- ●Use
pip freeze > requirements.txtto save your installed libraries. - ●Use
pip install -r requirements.txtto reinstall libraries from the file. - ●Add
env/to your.gitignoreto prevent uploading the virtual environment to GitHub.