Created
Sep 1, 2025 10:05 PM
Tags

Comprehensive Guide on python3 -m venv .venv
This guide covers all aspects of using Python's venv module, including installation, activation, deactivation, renaming the virtual environment, installing packages, and managing dependencies using requirements.txt.
‣
1. Installation of Python and venv
‣
2. Creating a Virtual Environment
‣
3. Activating the Virtual Environment
‣
4. Upgrade pip
‣
5. Install Packages
‣
5. Lock the exact versions requirements.txt
‣
6. Installing Packages from requirements.txt
‣
7. Deactivating the Virtual Environment
‣
8. Renaming the Virtual Environment
‣
9. Removing the Virtual Environment
Full Workflow Example
Here’s how the entire process might look:
# 1. Create a virtual environment
python3 -m venv .venv
# 2. activate the environment
source .venv/bin/activate  
# 3. Upgrade pip and build tools
pip install --upgrade pip setuptools wheel
# 4. Install core development tools
pip install --upgrade notebook ipython ipykernel pip-tools jupytext
# 5. Install core data science libraries
pip install --upgrade numpy pandas matplotlib seaborn scikit-learn scipy plotly
# 6. Install additional useful libraries
pip install --upgrade requests python-dotenv tqdm rich
# 8. Generate requirements.txt for reproducibility
pip freeze > requirements.txt
Key Points
- Use 
.venvas a convention for the environment folder. - Always activate the virtual environment before installing packages.
 - Use 
requirements.txtto manage dependencies for portability. - Deactivate the environment when not in use.
 
This ensures your projects are well-isolated and maintainable!