intermediateModules & Packages
Virtual Environments
Isolate project dependencies with venv and pip.
In this lesson
01Creating Virtual Environments
Use venv to create isolated Python environments for each project.
Python
1# Create a virtual environment2python -m venv myenv34# Activate it5# Windows: myenv\Scripts\activate6# macOS/Linux: source myenv/bin/activate78# Install packages9pip install requests flask1011# Save dependencies12pip freeze > requirements.txt1314# Deactivate when done15deactivate
02Requirements File
Track and share project dependencies.
Python
1# requirements.txt2flask==3.0.03requests==2.31.04numpy>=1.24.056# Install from requirements7pip install -r requirements.txt