A comprehensive beginner's guide to creating and managing Python virtual environments using conda and venv.
| Command (Click to Copy) | Description |
|---|---|
| ๐ Standard Python: venv | |
python -m venv myenv | Create a new virtual environment named 'myenv'. |
source myenv/bin/activate | macOS/Linux: Activate the environment. |
.\myenv\Scripts\activate | Windows: Activate the environment. |
deactivate | Exit the current virtual environment. |
pip install -r requirements.txt | Install all dependencies listed in a text file. |
rm -rf myenv | Delete the environment (simply delete the folder). |
| ๐งช Data Science: Conda (Anaconda/Miniconda) | |
conda create --name myenv python=3.9 | Create a new environment with a specific Python version. |
conda activate myenv | Activate the specified conda environment. |
conda deactivate | Exit the current conda environment. |
conda env list | List all created conda environments on your system. |
conda install pandas | Install a package using the conda package manager. |
conda remove --name myenv --all | Permanently delete the entire environment. |
| ๐ ๏ธ Common Helper Commands | |
pip list | View all installed packages in the active environment. |
pip freeze > requirements.txt | Export current environment settings to a file. |
Categories: : Python