Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create conda env with both name and path specified

Tags:

anaconda

OS: Windows 10

It's fine to create an env with either name or path, but it doesn't work with both name and path:

Command:

conda create -name myname --prefix D:\proj\myconda\myname

Error:

conda create: error: argument -p/--prefix: not allowed with argument -n/--name

So how to create an env both with a specific name and path?

The benefit from that is:

  1. It's more convenient to remember a shorter nick name for the env.
  2. It's better to move the path to other drives to save space of the default C system drive in Windows OS.
like image 572
Jiongjiong Li Avatar asked Apr 03 '18 20:04

Jiongjiong Li


People also ask

How do you create a conda environment in a specific location?

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!

How do you activate two conda environments?

To activate your Conda environment, type source activate <yourenvironmentname> . Note that conda activate will not work on Discovery with this version. To install a specific package, type conda install -n <yourenvironmentname> [package] . To deactivate the current, active Conda environment, type conda deactivate .

Can you have multiple conda environments?

I'd like to mention one more thing here. While you can have multiple environments that contain different versions of Python at the same time on the same computer, you can't set up 32- and 64-bit environments using the same Conda management system.


2 Answers

create a folder wherever you want to keep you environment files, inside the folder run:

conda create --prefix=yourenvname

When you wish to use this env, move to the folder in which you ran the previous command and do:

source activate yourenvname

Or

You can run:

conda create --prefix=path/yourenvname 

This will create environment named "yourenvname" in the specified path.

like image 121
Mehul Jain Avatar answered Sep 28 '22 07:09

Mehul Jain


Create conda environment with prefix:

conda create --prefix=path/to/envname # C:\path\to\envname for Windows users

Make sure that the directory specified is added to envs_dirs configuration

conda config --append envs_dirs path/to/envname # again, change if using Windows

Tip: If you are keeping multiple environments under a directory (e.g. /path/to holds multiple conda environments), then you can

conda config --append envs_dirs path/to # again, change if using Windows

and conda will pick up on all environments stored in /path/to.

After this step, conda should recognize that you want to include envname in your named environments. You can verify with:

conda info --envs

which should return something like:

# conda environments:
#

envname     /path/to/envname

Finally, to activate the environment, all you should need to do is

conda activate envname # replace envname with your environment name from prefix
like image 32
Jack Moody Avatar answered Sep 28 '22 08:09

Jack Moody