58

Can I change the path /Users/nolan/miniconda/envs/ to another one when creating a virtual environment ? I'd like it to be specific to my project directory. (As we can do with virtualenv)

$conda info -e
Using Anaconda Cloud api site https://api.anaconda.org
# conda environments:
#
_build                   /Users/nolan/miniconda/envs/_build
myen3                    /Users/nolan/miniconda/envs/myen3
nolanemirot              /Users/nolan/miniconda/envs/nolanemirot
root                  *  /Users/nolan/miniconda
nono
  • 2,262
  • 3
  • 23
  • 32

5 Answers5

58

You can change the environments directory by editing your .condarc file found in your user directory. Add the following specifying the path to the directory you want:

envs_dirs:
  - /Users/nolan/newpath
John Morrison
  • 3,810
  • 1
  • 15
  • 15
  • 3
    Can we specify folders at env level? I mean, each env in a different folder – doraemon Sep 21 '17 at 11:08
  • 2
    When you specify an environment directory this is where conda will create the actual environment subdirectories. So what ever you specify as the base envs_dirs it will make a directory in that for each environment you create. I don't know that there is a way to specify entirely different base directory paths for different environments. Here is the documentation on this, https://conda.io/docs/user-guide/configuration/use-condarc.html#specify-environment-directories-envs-dirs – John Morrison Sep 21 '17 at 16:23
16

If you would like it to be relative to your project directory, use the --prefix flag: https://conda.io/docs/commands/env/conda-env-create.html?highlight=prefix

For example, if you use environment.yml files to define your environment and you want your environment to be created in the venv directory of your project you would use the following:

conda env create -f environment.yml --prefix venv

The conda create command also has the --prefix flag as well: https://conda.io/docs/commands/conda-create.html?highlight=prefix

I don't know if this was available as of the original posting, but it should be available as of Liu Sha's comment, and gets closer to answering the question in regards to "I'd like it to be specific to my project directory".

hulin003
  • 2,554
  • 2
  • 13
  • 9
  • 1
    The links are not more valid, but I think this is a good substitute: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#specifying-a-location-for-an-environment – Giacomo Catenazzi Feb 11 '22 at 08:43
12

If you need a one-liner instead of searching for your .condarc file, you can use the following command:

conda config --add envs_dirs /Users/nolan/newpath

7

conda create -p env-dir is the possible solution which i used where venv, virtualenv and even pipenv failed as I used berrycomda on my raspberrypi

JSelser
  • 3,510
  • 1
  • 19
  • 40
0

You can also configure this via an environment variable CONDA_ENVS_PATH. I found this useful configuring the location for all users on a system by adding the following to /etc/bashrc:

export CONDA_ENVS_PATH="$HOME/.conda/envs/"
Will Holtz
  • 677
  • 5
  • 17