Python Environment
Set up Python environments
Python Environment
Python
I prefer using Conda environment for managing Python packages, but you can also use Pythonβs built-in venv
module or pip
for package management.
Environments Management
1
2
3
4
5
# Create a virtual environment in the current directory
python3 -m venv py_env
# Create a virtual environment with a specific Python version
python3.9 -m venv my_py39_env
1
2
3
4
5
6
7
8
9
10
11
# Activate the environment on macOS/Linux
source py_env/bin/activate
# View installed packages in the environment
pip3 list
# Deactivate the active virtual environment
deactivate
# Delete the virtual environment folder (after deactivation)
rm -rf py_env
1
2
3
4
5
6
7
8
9
10
# Save the current environment's dependencies to a requirements file
pip3 freeze > requirements.txt
# Install all packages listed in a requirements.txt file
pip3 install -r requirements.txt
# --- requirements.txt ---
numpy==1.22.4
pandas==1.4.3
matplotlib>=3.3,<4.0
scikit-learn>=0.24
Package Management
1
2
3
4
5
6
7
8
9
# Upgrade pip to the latest version
pip3 install --upgrade pip
# Install specific packages
pip3 install jupyter
pip3 install pandas numpy matplotlib
# Uninstall a specific package
pip3 uninstall package_name
This post is licensed under CC BY 4.0 by the author.