How to activate an Anaconda environment from the command line?

29,788

To create an environment: conda create --name myenv

NOTE: Replace myenv with the environment name.

When conda asks you to proceed, type y:

proceed ([y]/n)?for more detail click this

about activate this may help

to add anaconda to path

In Windows, you will have to set the path to the location where you installed Anaconda3 to.

For me, I installed anaconda3 into C:\Anaconda3. Therefore you need to add C:\Anaconda3 as well as C:\Anaconda3\Scripts\ to your path variable, e.g. set PATH=%PATH%;C:\Anaconda3;C:\Anaconda3\Scripts.

Share:
29,788

Related videos on Youtube

Seppukki
Author by

Seppukki

Hobbyist programmer.

Updated on July 09, 2022

Comments

  • Seppukki
    Seppukki almost 2 years

    I'm trying to access a module which is installed in a virtual environment, but the problem I've run into is that I can't activate my environment from the command line (Windows cmd).

    Is there a command to activate an environment from the command line?

    It is for a Python project. So if you can find a solution to open the Anaconda command line and execute commands there, it would be also great.

    • cvanelteren
      cvanelteren over 5 years
      source activate [env] or conda activate [env] edit: make sure conda is in your windows path.
    • Seppukki
      Seppukki over 5 years
      It isn't in my path, how to add it?
    • cvanelteren
      cvanelteren over 5 years
      Did you read the install instructions. Edit additionally IIRC during installation on windows there is a box you should tick to add it to path.
    • Seppukki
      Seppukki over 5 years
      No I didn't, but it's already installed. How can I add it to my pat?
    • cvanelteren
      cvanelteren over 5 years
      You can add it to path by going to Edit environment variables and then adding conda ex to path. First you should locate where you installed conda executable.
    • cvanelteren
      cvanelteren over 5 years
      However redoing the installation with the box ticked will be easier.
    • double-beep
      double-beep over 5 years
      So, what does where /r "C:\" conda.exe says in cmd?
    • Seppukki
      Seppukki over 5 years
      I get a lot of lines output, but I think I need this one: C:\Users\user\Anaconda3\Scripts\conda.exe
    • double-beep
      double-beep over 5 years
      Where is conda installed?
    • darthbith
      darthbith over 5 years
      Don't put Anaconda on your PATH (it is not recommended by Anaconda). Instead, use the Anaconda Prompt.
    • Seppukki
      Seppukki over 5 years
      But can I open the Anaconda prompt with python and execute commands in it?
    • darthbith
      darthbith over 5 years
      No, you run Python from within the Anaconda Prompt. The Anaconda Prompt is opened from, e.g., the Start Menu.
    • Seppukki
      Seppukki over 5 years
      I think you don't get it... I want to write a script which accesses the command line (CMD or anaconda)
    • jww
      jww over 5 years
      Stack Overflow is a site for programming and development questions. You should use another site on the Stack Exchange network for this question.
    • Seppukki
      Seppukki over 5 years
      Can you suggest a site?
    • Soren
      Soren about 5 years
      This question is very specific and should be re-opened.
  • Seppukki
    Seppukki over 5 years
    conda isn't in my path and where conda doesn't return anything usefull, how can I add conda to my path?
  • Seppukki
    Seppukki over 5 years
    I already have an environment.
  • Seppukki
    Seppukki over 5 years
    That's not what i want, I want to open my environment using the command line.
  • hash_ir
    hash_ir over 5 years
    By environment do you mean your virtual env or the deafult conda env?
  • hash_ir
    hash_ir over 5 years
    For either of the case, add conda to your environment variable (user variable). It generally is C:\ProgramData\Anaconda3 but check for yours. And ProgramData is a hidden folder.
  • Seppukki
    Seppukki over 5 years
    how should I name the environment variable
  • Seppukki
    Seppukki over 5 years
    and do i need to use the path to the \Anacond folder or to the conda.exe file?
  • Seppukki
    Seppukki over 5 years
    When I run the 'path' command, I can use the conda command but i get an error when i run conda activate, it's to big to post here but i says that my shell has not properly been configured for conda activate. the solutions provided in the error are for linux... what now?
  • hash_ir
    hash_ir over 5 years
    You don't have to name it. In the user variable "path", just add an entry for the Anaconda folder. That will do it!!
  • Seppukki
    Seppukki over 5 years
    Thx for the support!
  • Soren
    Soren about 5 years
    You are answering a different question. The question is about starting a conda environment from cmd.exe and specifically not the anaconda prompt.
  • wjakobw
    wjakobw almost 5 years
    Since this came up when I websearched the issue, a note for posterity: After adding "my_install_location/Anaconda3/condabin" to the PATH environment variable, I can use conda commands in cmd.exe, without the Anaconda Prompt. (This works through the .bat-files "conda.bat" and "activate.bat" that are in condabin.)
  • mr3
    mr3 over 4 years
    this worked for me in a .cmd: set PATH=_<conda base install folder>_\Scripts;_<conda base install folder>_;%PATH% call conda.bat init cmd.exe call conda.bat activate _<desired environment name>_ <do stuff in the env>
  • Lucas925
    Lucas925 over 3 years
    Does not answer the question that was asked