Conda Environment Management Commands | DevTools

Master Conda environment management with essential commands. Learn to create, activate, deactivate, clone, list, and remove Conda environments efficiently.

Conda Environment Management

Conda is a powerful open-source package management system and environment management system that runs on Windows, macOS, and Linux. It was created for the Python programming language but can package and distribute software for any language. This page provides essential Conda commands for efficient environment management.

Conda Environment Commands

Managing your project dependencies is crucial for reproducibility and avoiding conflicts. Conda simplifies this process with a set of intuitive commands.

Listing and Creating Environments

# To list all Conda environments
conda env list

# To create a new Conda environment
conda create --name <environment_name>

# To create a new environment with a specific Python version (e.g., Python 3.10)
conda create --name <environment_name> python=3.10

# To install packages from a requirements file
conda install --file <requirements.txt>

# To clone an existing environment
conda create --clone <old_environment_name> --name <new_environment_name>

Activating and Deactivating Environments

Switching between environments is straightforward, allowing you to isolate project dependencies.

# To activate a virtual environment
conda activate <environment_name>

# To deactivate the current virtual environment
conda deactivate

Managing Environments and Packages

These commands help you maintain and export your environment configurations.

# To remove an environment by name
conda env remove --name <environment_name>
# Alternatively, remove by prefix (path to environment)
conda env remove --prefix <path/to/env>

# To list all packages installed in a specific environment
conda list --name <environment_name>

# To list packages in the currently activated environment
conda list

# To export the current environment to a YAML file (includes all dependencies)
conda env export > <environment.yml>

# To export only manually installed packages (excluding dependencies)
conda env export --from-history > <environment.yml>

External Resources