How to activate an Anaconda environment

617,480

Solution 1

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?

Solution 2

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

Solution 3

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)

Solution 4

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

Solution 5

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.

Share:
617,480

Related videos on Youtube

pandita
Author by

pandita

Updated on February 10, 2021

Comments

  • pandita
    pandita about 3 years

    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?

    • remram
      remram about 9 years
      Ran into this today. Looks very much likes a bug, reported as conda-env#59
  • pandita
    pandita over 10 years
    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...
  • Asad Saeeduddin
    Asad Saeeduddin about 9 years
    I don't understand what the point of activate is if it doesn't set the path variable for me.
  • remram
    remram about 9 years
    It's a bug. I sent a fix, hopefully the next version works correctly.
  • phillipsK
    phillipsK about 9 years
    on Windows, use the activate command in the cmd prompt terminal
  • Clever Programmer
    Clever Programmer over 8 years
    export PATH="/$HOME/anaconda/bin:$PATH" will work for MAC OS X users. That's what I did to get my virtualenvs to work.
  • kon psych
    kon psych almost 8 years
    I used powershell and the above method does not work. On cmd however it works fine.
  • Tshilidzi Mudau
    Tshilidzi Mudau over 6 years
    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 ?
  • Shital Shah
    Shital Shah almost 4 years
    you don't need -n for activate. Just conda activate base is good enough.
  • Vijayanand Settin
    Vijayanand Settin almost 3 years
    This is the one that worked for me. After I did 'activate base', (base) appeared at the top of my bash shell.
  • Steve Scott
    Steve Scott about 2 years
    what if you want to use PowerShell?