232

I'm on Windows 8, using Anaconda 1.7.5 64bit.

I created a new Anaconda environment with

conda create -p ./test python=2.7 pip

from C:\Pr\TEMP\venv\.

This worked well (there is a folder with a new python distribution). conda tells me to type

activate C:\PR\TEMP\venv\test

to activate the environment, however this returns:

No environment named "C:\PR\temp\venv\test" exists in C:\PR\Anaconda\envs

How can I activate the environment? What am I doing wrong?

1
  • 1
    Ran into this today. Looks very much likes a bug, reported as conda-env#59
    – remram
    Commented Feb 20, 2015 at 17:28

15 Answers 15

209

If this happens you would need to set the PATH for your environment (so that it gets the right Python from the environment and Scripts\ on Windows).

Imagine you have created an environment called py33 by using:

conda create -n py33 python=3.3 anaconda

Here the folders are created by default in Anaconda\envs, so you need to set the PATH as:

set PATH=C:\Anaconda\envs\py33\Scripts;C:\Anaconda\envs\py33;%PATH%

Now it should work in the command window:

activate py33

The line above is the Windows equivalent to the code that normally appears in the tutorials for Mac and Linux:

$ source activate py33

More info: https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/8T8i11gO39U

Does `anaconda` create a separate PYTHONPATH variable for each new environment?

6
  • 11
    I don't understand what the point of activate is if it doesn't set the path variable for me. Commented Feb 22, 2015 at 22:41
  • 7
    It's a bug. I sent a fix, hopefully the next version works correctly.
    – remram
    Commented Feb 24, 2015 at 18:27
  • 3
    on Windows, use the activate command in the cmd prompt terminal
    – phillipsK
    Commented Apr 3, 2015 at 5:05
  • 2
    export PATH="/$HOME/anaconda/bin:$PATH" will work for MAC OS X users. That's what I did to get my virtualenvs to work. Commented Aug 24, 2015 at 4:52
  • 8
    I used powershell and the above method does not work. On cmd however it works fine.
    – kon psych
    Commented May 26, 2016 at 20:33
153

Use cmd instead of Powershell! I spent 2 hours before I switched to cmd and then it worked!

create Environment:

conda create -n your_environment_name

see list of conda environments:

conda env list

activate your environment:

conda activate your_environment_name

That's all folks

3
  • 2
    what if you want to use PowerShell? Commented Apr 19, 2022 at 14:33
  • 2
    Switching from Powershell to cmd did the trick. Thanks! Commented May 10, 2023 at 20:07
  • 1
    @SteveScott you need to run conda init powershell as explained in this stackoverflow answer. I also run conda config --set auto_activate_base false
    – JVal90
    Commented Jun 21, 2023 at 16:20
21

All the former answers seem to be outdated.

conda activate was introduced in conda 4.4 and 4.6.

conda activate: The logic and mechanisms underlying environment activation have been reworked. With conda 4.4, conda activate and conda deactivate are now the preferred commands for activating and deactivating environments. You’ll find they are much more snappy than the source activate and source deactivate commands from previous conda versions. The conda activate command also has advantages of (1) being universal across all OSes, shells, and platforms, and (2) not having path collisions with scripts from other packages like python virtualenv’s activate script.

Examples

conda create -n venv-name python=3.6
conda activate -n venv-name
conda deactivate

These new sub-commands are available in "Aanconda Prompt" and "Anaconda Powershell Prompt" automatically. To use conda activate in every shell (normal cmd.exe and powershell), check expose conda command in every shell on Windows.

References

4
  • 1
    you don't need -n for activate. Just conda activate base is good enough. Commented Jun 27, 2020 at 23:18
  • Noobie question => Is "venv-name" hard coded here or does it actually represent a path to a venv for a given project? Sounds like the simple answer is from Shital and should be "conda activate base"?
    – Jamie
    Commented Oct 28, 2022 at 13:14
  • @Jamie venv-name represents a specific virtual environment name. base is the default virtual environment name where conda (conda is a command written in Python) is installed. My another answer may shed some light about this. stackoverflow.com/a/58112484/5101148
    – Simba
    Commented Oct 31, 2022 at 2:27
  • Oddly, as the venv-name is not base but (in my case 'pyspark3', One of the bigger issues I'm facing is that as the environment variables are adjusted to fit a scenario,, they machine requires a reboot before the registry can resolve the change. It would be nice if the Environment variable could be tied to the venv name.
    – Jamie
    Commented Nov 1, 2022 at 12:01
20

Note that the command for activating an environment has changed in Conda version 4.4. The recommended way of activating an environment is now conda activate myenv instead of source activate myenv. To enable the new syntax, you should modify your .bashrc file. The line that currently reads something like

export PATH="<path_to_your_conda_install>/bin:$PATH"

Should be changed to

. <path_to_your_conda_install>/etc/profile.d/conda.sh

This only adds the conda command to the path, but does not yet activate the base environment (which was previously called root). To do also that, add another line

conda activate base

after the first command. See all the details in Anaconda's blog post from December 2017. (I think that this page is currently missing a newline between the two lines, it says .../conda.shconda activate base).

(This answer is valid for Linux, but it might be relevant for Windows and Mac as well)

0
9

As you can see from the error message the paths, that you specified, are wrong. Try it like this:

activate ..\..\temp\venv\test

However, when I needed to install Anaconda, I downloaded it from here and installed it to the default paths (C:\Anaconda), than I put this path to the environment variables, so now Anacondas interpreter is used as default. If you are using PyCharm, for example, you can specify the interpreter there directly.

1
  • I'm am specifying the path where the anaconda environment is installed. I copied the ` activate ...` directly from the conda create output and tried running it from C:/ as well as from C:/pr/temp/venv. Still it doesn't work...
    – pandita
    Commented Nov 19, 2013 at 21:08
8

I've tried to activate env from Jenkins job (in bash) with conda activate base and it failed, so after many tries, this one worked for me (CentOS 7) :

source /opt/anaconda2/bin/activate base
5

Below is how it worked for me

  1. C:\Windows\system32>set CONDA_ENVS_PATH=d:\your\location
  2. C:\Windows\system32>conda info

Shows new environment path

  1. C:\Windows\system32>conda create -n YourNewEnvironment --clone=root

Clones default root environment

  1. C:\Windows\system32>activate YourNewEnvironment

Deactivating environment "d:\YourDefaultAnaconda3"... Activating environment "d:\your\location\YourNewEnvironment"...

  1. [YourNewEnvironment] C:\Windows\system32>conda info -e

conda environments: #

YourNewEnvironment
* d:\your\location\YourNewEnvironment

root d:\YourDefaultAnaconda3

4

Though @Simba had a good answer at the time, a lot has changed in the conda env since 4.6. Conda activate (env-name) overthrew source activate (env-name) for good but not without it own challenges. conda activate oftentimes forces your environment to base and makes you see something like this:

(base)

and throwing loads of error back at you. This can also be because auto_activate_base is set to True.

You can check this by using the following command

conda config --set auto_activate_base False
source ~/.bashrc

And to reactivate use this

conda config --set auto_activate_base True
source ~/.bashrc
3

let's assume your environment name is 'demo' and you are using anaconda and want to create a virtual environment:

(if you want python3)

    conda create -n demo python=3

(if you want python2)

    conda create -n demo python=2

After running above command you have to activate the environment by bellow command:

    source activate demo 
1
  • source activate demo or conda activate demo?
    – jtlz2
    Commented Nov 30, 2023 at 14:46
3

For me, using Anaconda Prompt instead of cmd or PowerShell is the key.

In Anaconda Prompt, all I need to do is activate XXX

1
  • This is the one that worked for me. After I did 'activate base', (base) appeared at the top of my bash shell. Commented Aug 4, 2021 at 14:40
0

I was having the same, a fix seems to have been made in the source.

1
  • 2
    Hi @Nelson, note that, the link you supplied is now down. maybe put the instructions that were contained in that link in your answer instead ? Commented Sep 12, 2017 at 13:16
0

One special case: If you are trying to put the activation command in a unix script, you might run into a problem because when you run the bash script, a new (linux) shell environment is created, and then destroyed when you exit that script. Think of this as running bash, then source activate... / conda activate..., then running exit to exit that shell... The result is you end up without an activated shell... More details in How to execute script in the current shell on Linux?:

TL;DR: for linux, to activate in a bash script and leave active:

  1. Add the line #!/bin/bash as the first line of the script (This is anyways always a good practice, it specifies this is a bash script)
  2. Type the command source shell_script.sh or . shell_script.sh

Note: . in bash is equivalent to source in bash.

0

I'm using conda with Windows 10. Anaconda was installed in:

C:\User\Admin\Anaconda3

After installation I've added this folders to system PATH:

C:\User\Admin\Anaconda3
C:\User\Admin\Anaconda3\Scripts

Then I ran "Anaconda promt" from windows start menu. From this anaconda promt I created my environment with

conda create --name my_env

And after that, I'm able to activate my conda environment from regular CMD by just typing:

activate my_env
0

For me running this works in VS Code:

C:/ProgramData/Anaconda3/Scripts/activate

Or just creating a new Terminal.

-1

Window: conda activate environment_name

Mac: conda activate environment_name

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