Skip to main content
Environments in conda are self-contained, isolated spaces where you can install specific versions of software , including dependencies, libraries, and Python versions. This isolation helps avoid conflicts between package versions and ensures that your projects have the exact libraries and tools they need. For more information on environments, see our environments concepts page.

Working with environments

For convenience, the most common actions users take when managing environments are detailed here. For a full list of actions and more comprehensive guide, see Manage environments in the official conda documentation. Alternatively, follow along with our Getting started with conda environments tutorial on Anaconda.com.
If you prefer to create and manage your environments via our graphical interface, Navigator, see Managing environments.

Creating an environment

Create a by opening Anaconda Prompt (Terminal on macOS/Linux) and following the steps for your use case below:
  • Creating a new environment
  • Creating an environment from a `.yml` file
The following command creates a new environment and downloads the specified packages and their dependencies:
# Replace <ENV_NAME> with a name for your environment
# Replace each <PACKAGE> with the name of your desired packages
# Replace <VERSION> with your desired version (optional)
conda create --name <ENV_NAME> <PACKAGE>=<VERSION> <PACKAGE> <PACKAGE>
Example environment creation command
conda create --name myenv python=3.11 beautifulsoup4 docutils jinja2=3.1.4 wheel
Version matching utilizes MatchSpec Protocol. Below are some examples for specifying versions for packages when creating an environment. If you do not specify a package version, conda will attempt to install the latest version of the package from its available .
  • python=3.12.1 - Matches the package with the exact name and version specified.
  • python>=3.11 - Matches any version of the package that is greater than or equal to the version specified.
  • python<=3.12 - Matches any version of the package that is less than or equal to the version specified.
  • python>3.10,<3.12 - Matches any version of the package between the specified versions, but excludes the specified versions.
  • python>=3.10,<=3.12 - Matches any version of the package between the specified versions, including the specified versions.
  • python[version='3.12.*'] - Matches any version of the python package that starts with 3.12.
It is best practice to install all of the packages that you need in your environment in a single command. This reduces the risk of dependency conflicts or broken environments.
When you create an environment, conda it to the environments.txt file, which is located here:
  • Windows
  • macOS/Linux
%USERPROFILE%\.conda\environments.txt
conda --info envs uses the environments.txt file to show all existing environments on your machine, even those outside the base install directory.

Environment locations

By default, conda creates environments in the following locations, depending on your operating system and how you’ve installed conda:
Operating SystemInstallerDefault Environment Location
WindowsGraphical installer (.exe)
  • C:\Users\<USERNAME>\anaconda3\envs\
  • C:\Users\<USERNAME>\miniconda3\envs\
macOSGraphical installer (.pkg)
  • /opt/anaconda3/envs/
  • /opt/miniconda3/envs/
macOSCommand line installer (.sh)
  • /anaconda3/envs/
  • /miniconda3/envs/
LinuxCommand line installer (.sh)
  • /anaconda3/envs/
  • /miniconda3/envs/
You can specify the path where you want the environment to be created by including the --prefix command when creating an environment, or by updating your .condarc file to contain the envs_dirs: key.
Example .condarc configuration
channels:
  - defaults
default_channels:
  - https://repo.anaconda.com/pkgs/main
envs_dirs:
  - /Users/<USER>/conda-envs

Activating an environment

Because environments are isolated spaces, you can only work with one at a time. Selecting an environment to work with is called activating it. Activate an environment by running the following command:
# Replace <ENV_NAME> with the name of the environment you want to activate
conda activate <ENV_NAME>

Switching between environments

When you’re ready to switch between projects, simply activate the environment of your other project. Activating a different environment will deactivate your current one.
  1. (Optional) View a list of all your environments by running the following command:
    conda info --envs
    
  2. To switch to a different environment, activate it by running the following command:
    # Replace <ENV_NAME> with the name of the environment you want to switch to
    conda activate <ENV_NAME>
    

Locking an environment

The most reliable way to ensure your project remains reproducible indefinitely is to “lock” its environment. Locking an environment creates a fully specified environment, one that has all packages used in the project and their dependencies configured to a specific version. This ensures that your project will be reproduced exactly as it was initially configured, because there will never be an unexpected update or change if new package dependencies are released. Locking your project requires the conda-project package to be installed in the environment you want to lock. Install the package by running the following commands:
# Replace <ENV> with the environment you want to lock
conda activate <ENV>
conda install conda-project
If your project doesn’t contain an environment.yml file, create one by running the following command:
conda-project init
You can then lock your project’s environment by running the following command:
conda-project lock
Locking your project produces a conda-lock.default.yml file that you can export to share with others.

Sharing an environment

Sharing your environment with someone else allows them to use conda to recreate your environment on their machine. To share an environment and its software packages, you must export your environment’s configurations into a .yml file.
Simply copying your Anaconda or Miniconda files over to a new directory or another machine will not recreate the environment. You must export the environment as a whole.

Exporting the environment configuration .yml file

If you already have an environment configuration .yml file in your current directory, it will be overwritten during the export process.
  1. Activate the environment you want to export by running the following command:
    # Replace <ENV_NAME> with the name of the environment you want exported
    conda activate <ENV_NAME>
    
  2. Export the environment by running the following command:
    conda env export > environment.yml
    
    The environment.yml file populates in your current working directory.
    This operation includes both the environment’s conda and pip packages.
  3. Share the exported environment configuration .yml file with another user.

Deactivating an environment

It is best practice to deactivate your environment when you are finished working in it. To deactivate your active environment, run the following command:
conda deactivate
When you deactivate an environment, conda returns to the previously activated environment.For example, if you run conda activate my_env1, followed by conda activate my_env2, and then run conda deactivate, conda returns to the my_env1 environment.

Removing an environment

To remove an environment, run the following command:
conda remove --name <ENV_NAME> --all
Running conda remove deletes and your environment.
If, for any reason, you need to delete an environment directory manually, don’t use your file explorer. If you do, you’ll remove the environment’s contents and free up space on your machine, but leave the environment path listed in your environments.txt file (see Environment registration).To manually delete and deregister an environment directory properly, run one of the following commands, depending on your operating system and conda installation:
  • Windows
  • macOS/Linux
# Replace <PATH_TO_ENV_DIRECTORY> with the path to the directory that contains the environments
C:\Users\<YOUR_USERNAME>\anaconda3\_conda constructor uninstall --prefix <PATH_TO_ENV_DIRECTORY>