2

When I open the anaconda prompt the window that opens, shows:

(base) C:\Users\sherv>

So I deactivate it and get:

C:\Users\sherv>

which is the same thing when I open cmd. From here there is there any way that I can reactivate conda? Because the command words like "conda -v" or "activate base", etc, don't work.

Also, the conda prompt is a shortcut so when I right-click and select "open file location", it goes to windows\system32\cmd. So I don't understand why I can't activate conda environments from cmd if it's the same thing?

This is the anaconda prompt shortcut: Anaconda Prompt.lnk

When I open file location its the cmd: After I open file location

I have even tried to add it to that path just in case it might work?

file path

PS. I'm very new to all this and trying to connect some dots; sorry if it's a stupid question.

ok, so the path first opens the cmd (which is why the shortcut points at it, but then from there, from within the cmd, it runs C:\Users\sherv\Anaconda3\Scripts\activate.bat. Is there anyway I can have the batch file commands run from cmd without having to write out the path every time? I added the path for the batch file but it didn't work

7
  • How about conda activate base? Commented Sep 23, 2018 at 12:28
  • Did you try source activate yourenvname Commented Sep 23, 2018 at 14:04
  • @Lukasz 'conda' is not recognized as an internal or external command, operable program or batch file. Commented Sep 25, 2018 at 13:17
  • Neither is 'source' @Aaron Mazie Commented Sep 25, 2018 at 13:17
  • That means Anaconda is not on your PATH. Either add it to the path or navigate to the folder where the conda binary is. Commented Sep 25, 2018 at 13:24

2 Answers 2

3

I figured out how to do it, in my case with miniconda so it might be slightly different.

  1. Find conda.exe in the Scripts folder. For me it was C:\Users\[SomeUser]\miniconda3\Scripts\conda.exe
  2. Open command prompt and navigate to that same directory
  3. Run conda init cmd.exe - To see more info on this command, you can run conda init --help, where it says "Initialize conda for shell interaction. [Experimental]"
  4. Now after reloading command prompt, from anywhere you should be able to do conda activate WhateverEnvName and it will start it in that environment

If you want to make a batch file that opens to the environment, you can use cmd.exe /k conda activate WhateverEnvName


Alternatively, if you don't want to just open the environment, but actually want to launch a python script directly using that environment, you can type the full path to the python.exe in that environment folder, and then the relative path of the python script to run with that environment.

For example, say you open the command prompt in some arbitrary directory that contains "myscript.py" that you want to run with an environment called "whateverEnv".

You'd do: C:\Users\SomeUserName\miniconda3\envs\whateverEnv\python.exe myscript.py

You could also put that same line into a batch file.

2

The reason why the anaconda prompt shortcut leads to cmd is because it needs to open cmd first and then run a batch file which activates the conda environment. What I had done was to add the batch file to the path but I wasn't using the correct commands to run the conda environment. Therefore, all the keywords such as activate etc didn't work.

Simply type activate.bat and the file which is added to the path is opened which takes you to the base conda environment.

You can use this method to run different programs on different APIs and export the result back and analyse it.

Thanks for downvoting my question :)

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.