the default location for packages is .conda folder in my home directory. however, on the server I am using, there is a very strict limit of how much space I can use, which basically avoids me from putting anything under my home directory. how can I specify the location for the virtual environment that I want to create? Thanks! server is running Ubuntu.
-
15Is there something wrong with the answer or why have you not accepted it? You can always leave comments if there is something you don't like. – Charlie Parker Sep 17 '16 at 03:44
-
5@linX Always be sure to upvote answers you like, and accept the answer which is best or which solves your issue. This gives the authors a minor award and incentivizes them to continue to give well-thought and helpful answers. – Mike Williamson Mar 20 '19 at 18:19
8 Answers
Use the --prefix
or -p
option to specify where to write the environment files. For example:
conda create --prefix /tmp/test-env python=2.7
Will create the environment named /tmp/test-env
which resides in /tmp/
instead of the default .conda
.

- 5,473
- 1
- 30
- 37
-
9but once you have moved location of the env, how does conda know how to find where that new env is at? – Charlie Parker Sep 17 '16 at 03:41
-
8there is a directory for each environment inside of ~/.conda/envs. Follow the guidance of others and use --prefix to install wherever you want. Then create a symlink from one to another: ln -s /shared/eng/conds/envs/test-env ~/.conda/envs/test-env – Robert Lugg Sep 19 '17 at 17:44
-
2why doesn't `conda create --name hbf_env --prefix /om2/user/username python=3.6 ` work? says `-bash: /home/username/.conda/envs/hbf_env/bin/conda: No such file or directory`? – Charlie Parker Oct 05 '17 at 21:19
-
7Charlie, I'm not sure why you got the error message about missing file/directory, but regardless of that, `--name` cannot be used with `--prefix`. Assuming conda is installed correctly, the corresponding command would be `conda create --prefix /om2/user/username/hbf_env python=3.6`. This would create an env named `hbf_env` in location `/om2/user/username/` – Thomas Fauskanger Nov 23 '17 at 02:55
-
13@ThomasFauskanger it looks like the prefix command does not create a name for the environment, at least for me.. After `conda create --prefix hbf_env` in the local directory, `conda info --envs` shows blank for name but does show the full path... activating the environment necessitates that I type out the full path (conda cannot find the environment if I just type the name) – Joshua Zastrow Apr 23 '18 at 14:31
-
Using miniconda, I create symlinks like this: `ln -s /apps/conda/testenv ~/miniconda3/envs/testenv`. Conda then does not need the full path for activation, but `conda activate testenv` works just fine. – rvf Mar 14 '20 at 11:26
-
2If there is any reason I might ever stop using python it is virtualenv's... the solutions never really work as seemlessly as their supposed to... arghhhhhh – Zephaniah Grunschlag Dec 27 '20 at 05:30
like Paul said, use
conda create --prefix=/users/.../yourEnvName python=x.x
if you are located in the folder in which you want to create your virtual environment, just omit the path and use
conda create --prefix=yourEnvName python=x.x
conda only keep track of the environments included in the folder envs inside the anaconda folder. The next time you will need to activate your new env, move to the folder where you created it and activate it with
source activate yourEnvName

- 963
- 6
- 10
-
4Note that if you forgot the environment name you can use the FULL path of the directory containing your environment – tjb Aug 05 '17 at 03:41
-
4You can tell conda to look for envs in other locations using the `.condarc` configuration file. https://conda.io/docs/user-guide/configuration/use-condarc.html#specify-environment-directories-envs-dirs – Harsh Dec 13 '17 at 00:17
-
This creates an environment without a name, only the directory. Is there any way to create a name within the statement? Conda won't let me specify both. – Kyouma Feb 05 '20 at 00:41
While using the --prefix
option works, you have to explicitly use it every time you create an environment. If you just want your environments stored somewhere else by default, you can configure it in your .condarc
file.
Please see: https://conda.io/docs/user-guide/configuration/use-condarc.html#specify-environment-directories-envs-dirs

- 2,548
- 1
- 22
- 23
-
16If you haven't already changed this variable, you can configure it by running this one command: `conda config --append envs_dirs /path/to/envs` – Arthur Tacca Nov 19 '18 at 10:46
-
8Also add `env_prompt: ({name})` to ~/.condarc if you get full path in your prompt. – plonker13 Sep 05 '19 at 20:16
-
1This is probably a REALLY specific case, but you need to ensure you have write access to the folder specified in `envs_dirs` in order for `conda create` to use it as default. Implementation is for `conda create` to use the first listed, writable directory (`anaconda3/lib/site-packages/conda/base/context.py`, `_first_writable_envs_dir` function). – Ben Saunders Dec 14 '21 at 00:09
If you want to use the --prefix
or -p
arguments, but want to avoid having to use the environment's full path to activate it, you need to edit the .condarc
config file before you create the environment.
The .condarc
file is in the home directory; C:\Users\<user>
on Windows. Edit the values under the envs_dirs
key to include the custom path for your environment. Assuming the custom path is D:\envs
, the file should end up looking something like this:
ssl_verify: true
channels:
- defaults
envs_dirs:
- C:\Users\<user>\Anaconda3\envs
- D:\envs
Then, when you create a new environment on that path, its name will appear along with the path when you run conda env list
, and you should be able to activate it using only the name, and not the full path.
In summary, if you edit .condarc
to include D:\envs
, and then run conda env create -p D:\envs\myenv python=x.x
, then activate myenv
(or source activate myenv
on Linux) should work.
Hope that helps!
P.S. I stumbled upon this through trial and error. I think what happens is when you edit the envs_dirs
key, conda updates ~\.conda\environments.txt
to include the environments found in all the directories specified under the envs_dirs
, so they can be accessed without using absolute paths.

- 441
- 4
- 5
You can create it like this
conda create --prefix C:/tensorflow2 python=3.7
and you don't have to move to that folder to activate it.
# To activate this environment, use:
# > activate C:\tensorflow2
As you see I do it like this.
D:\Development_Avector\PycharmProjects\TensorFlow>activate C:\tensorflow2
(C:\tensorflow2) D:\Development_Avector\PycharmProjects\TensorFlow>
(C:\tensorflow2) D:\Development_Avector\PycharmProjects\TensorFlow>conda --version
conda 4.5.13

- 3,002
- 5
- 28
- 42
-
3While the OP said they were using Ubuntu, +1 for also providing the solution on a Windows machine. :) – Mike Williamson Mar 20 '19 at 18:23
I ran into a similar situation. I did have access to a larger data drive. Depending on your situation, and the access you have to the server you can consider
ln -s /datavol/path/to/your/.conda /home/user/.conda
Then subsequent conda commands will put data to the symlinked dir in datavol

- 7,155
- 8
- 41
- 40
-
1This is the really-right answer, in my opinion -- the original question was about the location for packages, and has some ambiguity, but I recently ran into this issue, and did a bit of investigating. There are two important directories under `$HOME/.conda`, `envs` and `pkgs`. Using the `--prefix` scheme mentioned above builds the environment somewhere else, but all the package file downloads still go to `$HOME/.conda/pkgs`. The symlink solution offered here fixes both the environment *and* the download locations. – Andrew Reid Sep 24 '20 at 14:10
-
You can modify the default paths for environments by modifying CONDA_ENVS_PATH
:
For macOS and Linux: CONDA_ENVS_PATH=~/my-envs:/opt/anaconda/envs
For Windows: set CONDA_ENVS_PATH=C:\Users\joe\envs;C:\Anaconda\envs
the documentation is here: https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#specify-environment-directories-envs-dirs

- 117
- 7
Use -p
option to specify the path to your env.
For Linux/macOS, env location info is stored in ~/.conda/environments.txt
.
Use conda info --envs
to list all your envs.

- 1,234
- 1
- 13
- 20