Master Python Virtual Environments: conda & venv Guide

Master Python Virtual Environments: conda & venv Guide

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 myenvCreate a new virtual environment named 'myenv'.
source myenv/bin/activatemacOS/Linux: Activate the environment.
.\myenv\Scripts\activateWindows: Activate the environment.
deactivateExit the current virtual environment.
pip install -r requirements.txtInstall all dependencies listed in a text file.
rm -rf myenvDelete the environment (simply delete the folder).
๐Ÿงช Data Science: Conda (Anaconda/Miniconda)
conda create --name myenv python=3.9Create a new environment with a specific Python version.
conda activate myenvActivate the specified conda environment.
conda deactivateExit the current conda environment.
conda env listList all created conda environments on your system.
conda install pandasInstall a package using the conda package manager.
conda remove --name myenv --allPermanently delete the entire environment.
๐Ÿ› ๏ธ Common Helper Commands
pip listView all installed packages in the active environment.
pip freeze > requirements.txtExport current environment settings to a file.

Categories: : Python