The Definitive Guide to Conda Environments
Where Environments Live

When you create an environment with Python’s venv module, you need to say where it lives by specifying its path.

% python3 -m venv /path/to/new/environment

Environments created with conda , on the other hand, live by default in the envs/ folder of your Conda directory, whose path will look something like:

% /Users/user-name/miniconda3/envs # Or .../anaconda3/envs

I prefer the approach taken by venv for two reasons.

1️⃣ It makes it easy to tell if a project utilizes an isolated environment by including the environment as a sub-directory.

my-project/

├── conda-env # Project uses an isolated env ✅

├── data

├── src

└── tests

2️⃣ It allows you to use the same name for all of your environments (I use “conda-env”), meaning you can activate each with the same command.

% cd my-project/

% conda activate conda-env

💸 Bonus: This allows you to alias the activation command and stick it in your .bashrc file, making life a little bit simpler.

⚠️ Note: If you keep all of your environments in your Conda’s env/ folder, you’ll have to give each of them a different name, which can be a pain 😞.

So, how do you place environments outside of your Conda’s env/ folder? By using the --prefix flag instead of --name when creating an environment.

% conda create --prefix /path/to/conda-env # Or use -p

⚠️ Note: This makes an environment called “conda-env” in the specified path.

It’s as simple as that. However, placing environments outside of the default env/ folder comes with two drawbacks.

1️⃣ conda can no longer find your environment with the --name flag. Instead, you’ll need to pass the --prefix flag along with the environment’s full path. For example, when installing packages, which we’ll cover in the next section.

2️⃣ Your command prompt is no longer prefixed with the active environment’s name, but rather its full path.

(/path/to/conda-env) %

As you can imagine, this gets messy quickly. Like this doozy, for instance.

(/Users/user-name/data-science/project-name/conda-env) % # 😨

Fortunately, there’s an easy fix. You just need to modify the env_prompt setting in your .condarc file, which you can do with a single stroke.

% conda config --set env_prompt '({name}) '

⚠️ Note: This will edit your .condarc file if you already have one and create one if you do not. For more on modifying your .condarc file, see the docs.

Now your command prompt will only display the active environment’s name.

% conda activate /path/to/conda-env

(conda-env) % # Woohoo! 🎉

Last, you can view a list of all your existing environments.

% conda env list # conda environments:

#

/path/to/conda-env

base * /Users/username/miniconda3

r-env /Users/username/miniconda3/envs/r-env
['Matthew Sarmiento']
['Programming', 'Software Development', 'Data Science', 'Technology', 'Towards Data Science']