liminfo

Conda Reference

Free reference guide: Conda Reference

29 results

About Conda Reference

The Conda Reference is a searchable cheat sheet covering the complete Conda workflow for data scientists, machine learning engineers, and Python developers who manage complex dependency stacks. The Environment section covers the full lifecycle of a Conda environment: creating a new env with a specific Python version (conda create -n myenv python=3.11), activating and deactivating environments, listing all environments with conda env list, cloning an existing environment with --clone, and permanently removing one with conda env remove. Environments can also be created at a specific file system path using --prefix for project-local isolation.

The Package section covers everything needed for dependency management: installing single or multiple packages with conda install, pinning a specific version with conda install pkg=VERSION (e.g., pytorch=2.1.0), updating individual packages or all packages with conda update --all, removing packages with conda remove, listing installed packages with conda list, and searching for available versions with conda search using version specifiers like "tensorflow>=2.0". The Channel section explains how to add community channels like conda-forge with conda config --add channels, install from a specific channel with the -c flag, and control channel priority with conda config --set channel_priority strict to prevent dependency conflicts.

The Config and Export sections are essential for reproducible environments. conda config --set controls global Conda behavior — a commonly used setting is auto_activate_base false to prevent the base environment from activating at shell startup. The Export section covers the primary reproducibility workflow: conda env export > environment.yml to capture the exact environment state, conda env create -f environment.yml to recreate it on another machine, and the cross-platform variant conda env export --no-builds which omits build strings that are OS-specific. The conda run -n NAME command lets you execute a script inside an environment without activating it first, which is valuable for CI/CD pipelines and automation scripts.

Key Features

  • conda create -n NAME python=3.11 for environment creation with pinned Python version
  • conda activate, deactivate, env list, and env remove for environment lifecycle management
  • conda install PKG=VERSION for exact version pinning (e.g., pytorch=2.1.0)
  • conda update --all and conda update conda for package and Conda self-updates
  • conda config --add channels conda-forge and -c CHANNEL for channel management
  • conda config --set channel_priority strict to prevent dependency solver conflicts
  • conda env export > environment.yml and --no-builds for cross-platform reproducibility
  • conda run -n NAME for running commands in an environment without activating it

Frequently Asked Questions

What is the difference between conda and pip?

conda is both a package manager and an environment manager that handles non-Python dependencies (C libraries, CUDA, MKL) as first-class packages. It uses a SAT solver to resolve compatible versions across the entire environment. pip only manages Python packages and relies on the OS for non-Python libraries. For data science workloads involving NumPy, PyTorch, or TensorFlow, conda ensures that compiled binary packages are compatible with your system's CUDA and BLAS libraries, which pip cannot guarantee.

What is conda-forge and why should I use it?

conda-forge is a community-maintained channel that provides up-to-date conda packages for thousands of packages that may lag behind on the default Anaconda channel. It is often the source for the latest PyTorch, JAX, or scientific package versions. Add it with conda config --add channels conda-forge or use it per-install with conda install -c conda-forge pkg. When using conda-forge alongside the default channel, setting channel_priority strict prevents mixing incompatible packages from different channels.

What does conda config --set auto_activate_base false do?

By default, when you install Anaconda or Miniconda, the base environment is automatically activated in every new terminal session. This can interfere with system Python or other tools. Setting auto_activate_base false (via conda config --set auto_activate_base false) removes this automatic activation, so you must explicitly run conda activate base when you want the base environment. This is recommended for developers who also use system Python or pyenv.

What is the difference between conda env export and conda list --export?

conda env export generates a full environment.yml file that includes all packages and their exact versions, the Python version, pip packages, and channels. It is meant for recreating the complete environment with conda env create -f. conda list --export generates a simpler requirements.txt-style list compatible with conda install --file, but it does not capture pip packages or channel information. For full reproducibility, conda env export is preferred.

How do I use pip inside a Conda environment without breaking it?

Activate the target environment first with conda activate myenv, then run pip install. pip will install into the active Conda environment's site-packages. Best practice is to install as much as possible with conda first, then use pip only for packages unavailable on any conda channel. Avoid running pip as root or with --user inside a conda env, as this can install packages outside the environment. conda env export will capture pip-installed packages in the pip: section of environment.yml.

What is the purpose of conda env export --no-builds?

The full conda env export output includes build strings like numpy-1.26.0-py311h8a38eb7_0. Build strings encode the Python version, operating system ABI, and compilation flags, making them platform-specific. Using --no-builds omits these strings, producing a more portable environment.yml that can be created on a different OS (e.g., Linux vs macOS). The trade-off is slightly less reproducibility, as conda may choose different build variants on the target system.

How does conda create --prefix differ from conda create -n?

conda create -n NAME creates an environment in Conda's central environments directory (usually ~/miniconda3/envs/). conda create --prefix ./envs/myproject creates the environment at the specified path relative to the current directory. Prefix-based environments are useful for project-local isolation (similar to Node.js node_modules or Python venv), and the path is shown instead of the name in the shell prompt. The environment must be activated with conda activate ./envs/myproject (full path).

Can I use Conda in CI/CD pipelines?

Yes. The conda run -n NAME command executes a command inside a named environment without requiring shell activation, making it ideal for CI scripts. For example: conda run -n myenv python -m pytest tests/. You can also create the environment from environment.yml with conda env create -f environment.yml --name ci-env at the start of a pipeline. Micromamba (a C++ reimplementation of conda) is often used in CI for faster environment creation.