22

I am trying to re-enter my conda environment but I am having trouble doing so as when I type conda activate (evironment name) or source activate (environment name) both return the error 'Could not find conda environment.' This is very strange as when I type conda info --envs, I get this:

# conda environments:
#
base                  *  /Users/(my name)/anaconda3
                         /anaconda3/envs/(environment name)
2

3 Answers 3

57

Names and Prefixes

For a Conda environment to have a name it must be installed in one of the envs_dirs directories (see conda config --show envs_dirs). Creating an environment outside of one of those forfeits its "name-ability". Instead, one must use the path (called its prefix) to activate it, e.g.,

conda activate /anaconda3/envs/my_env

Other commands will require one to use the --prefix|-p flag to specify the environment. See the documentation on "Specifying the location for an environment".

Adding Other Env Locations

If one plans to frequently install in a different location than the default, then there is an option to add directories to the envs_dirs configuration variable. In this specific case, this would be

conda config --append envs_dirs /anaconda3/envs

Note that whatever directory one specifies in this command will become the de facto default for future installs using the --name|-n flag. If one still wants to keep the standard default (/Users/<user>/anaconda3/envs), then they should follow the above with

conda config --prepend envs_dirs /Users/<user>/anaconda3/envs

That is, this will let one pick up the "names" of the environments installed in /anaconda3/envs, but calling conda create -n foo would still create it in /Users/(my name)/anaconda3/envs/foo.

For documentation, see: conda config --describe envs_dirs

1

Once upon a time I had a similar problem in Windows in Visual Studio Code terminal when I run activate C:\...\myEnvironmentFolder with the message Could not find conda environment: C:... The following command helped me:

source C:/myPath/Anaconda3/etc/profile.d/conda.sh

Then running activate C:\...\myEnvironmentFolder gave the desired effect

If you have the problem like this in cmd console, then, probably, you forgot to set the path in

Control panel -> System -> Advanced system settings -> User / System variables -> Path -> Edit -> New ->
and add
C:\ProgramData\Anaconda3\Scripts
C:\ProgramData\Anaconda3
C:\ProgramData\Anaconda3\Library\bin
0

You can try using a different method to create a virtual environment, Open CMD and type pip install virtualenvwrapper-win and hit enter this would be your step 1. Step 2) mkvirtualenv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.