introduction-to-conda-for-data-scientists icon indicating copy to clipboard operation
introduction-to-conda-for-data-scientists copied to clipboard

Provide an example of how to create env by prefix but with a name

Open davidrpugh opened this issue 4 years ago • 1 comments

Want to show users how to create environment by prefix (i.e., in a particular location) but with a name so that it can be activated by name. This appears to be possible.

https://stackoverflow.com/questions/49638329/how-to-create-conda-env-with-both-name-and-path-specified

davidrpugh avatar Feb 23 '21 12:02 davidrpugh

Hi David,

While possible it is (I think) not best practice, because you can have ambiguous environment names this way. That is, one could end up accidentally creating two environments with the same name. Conda would not warn about this, neither at the time of creation or activation.

Here an example:

$ mkdir project1 project2                           # create two empty directories
$ conda create --prefix project1/env                # create named ("env") environment
$ conda config --append envs_dirs $(pwd)/project1   # make it discoverable by conda
$ conda create --prefix project2/env                # create another environment with the same name in a different path
$ conda config --append envs_dirs $(pwd)/project2 
$ conda env list                                    # list conda environments
# conda environments:
#
env        /home/user/project1/env
env        /home/user/project2/env
$ conda activate env
(/home/user/project1/env) $                         # the first environment was activated with no warning!

If you try this out on your own device don't forget to clean up your ~/.condarc file when cleaning up afterwards.

All that said, this behavior has been discussed in conda's repository and was not actively discouraged (https://github.com/conda/conda/issues/7831). Still, I believe it might be confusing to learners.

Different opinions on this welcome.

Best, Jesko

jeskowagner avatar Mar 04 '22 19:03 jeskowagner