The benefits of conda environments
Environments each maintain their own installations of programming languages, packages, libraries, and tools, completely separate from other environments on your system. Some of the many benefits of using conda environments specifically are:- Conda supports complex binary dependencies when installing.
- Conda can manage binary libraries written in programming languages other than Python, like C/C++.
- Conda’s package format works reliably across different operating systems (Windows, macOS, Linux) and architectures.
- There are many data science and scientific computing packages readily available for conda users.
- Conda environments each maintain their own copies of binary libraries, isolating paths to these libraries and preventing conflicts.
Why should I create a new environment?
There are several reasons you might want to create a new environment: Isolation of dependencies - Environments isolate software and their dependencies from the rest of the software installed on your machine. This means you can have both Python 3.9 and Python 3.10 installed on your machine and use both versions without encountering issues. Reproducibility - By creating an environment for each project, you can ensure that your code runs consistently across different machines. Lock your environment to ensure that it remains reproducible indefinitely, then share the environment configuration to allow others to replicate your setup. For more information on locking and sharing environments, see Environments. Ease of management - Conda provides tools to easily create, manage, and delete environments. You can quickly switch between environments, making it simple to manage multiple projects with different requirements. For more information on creating, managing, and deleting environments or switching between environments, see [Managing environemnts] in the official conda documentation. For more information on switching between environments, see Environments. Testing and development - Environments are perfect for testing new packages or libraries without affecting your stable development setups. You can experiment freely and remove the environment if things don’t work out, without impacting your other projects.How conda environments work
The “base” environment
When first installing and using conda, you probably saw references to something calledbase
or a “base environment”. This environment is where conda itself is installed, and should only be used for installing anaconda, conda, and conda-related packages, such as anaconda-client
or conda-build
.
For your projects, however, Anaconda strongly recommends creating new environments to work in. This protects your base environment from breaking due to complex dependency conflicts and allows you to easily manage and reproduce your environment on other machines.
Where environments are stored
Each of your conda environments is stored in a separate directory on your computer. By default, these environemnt directories are stored in the following directories, depending on your operating system.- Windows
- macOS/Linux
- Anaconda Distribution -
C:\Users\<USERNAME>\anaconda3\envs
- Miniconda -
C:\Users\<USERNAME>\anaconda3\envs
conda activate <ENVNAME>
), conda modifies your system’s PATH variable to point to that environment’s executables first. This means, for example, when you type python
to run code or a script, you’re using the version installed in your active environment, not the global one.
The typical environment workflow
The typical workflow with conda environments looks like the following:- Plan: Determine what packages your project needs using
conda search
or searching anaconda.org or your organization’s channels in Package Security Manager. - Create: Create a new environment with the necessary tools. It’s best practice to install all packages that your environment needs at the same time.
- Activate: Switch to using that environment, so that your environment’s packages and libraries become available to you.
- Install: Add any additional packages you discover you need, if necessary.
- Work: Develop your project using the isolated environment.
- Document: Export the environment specification (for example, an
environment.yaml
file) to share with colleagues or recreate the environment at a later date. - Delete: Once you are finished developing the project, remove the environment to save space.