'How to activate an environment in miniconda

I have to deal with python code on Windows, so I installed miniconda. The installer suggested not adding conda to the PATH, so I didn't. I have created an environment by using Anaconda Prompt conda create -n playground python=3.6 command, but now I am confused. If I activate the environment by using conda activate env it only activates in the Anaconda Prompt shell and not anywhere else. If I start a cmder or an editor, it cannot find python or conda or pip or anything python related. How do I use conda environments outside of the Anaconda Prompt?



Solution 1:[1]

The simple answer is - you don't. The activation is literally just some changes to the environment variables, mainly PATH. When you need to use a conda environment in some other program, you have two options:

  • If the program doesn't know anything about Python, make sure that the program is started with the correct environment variables. E.g. just start it from within the shell with the activated conda environment.

  • If the program does know about Python (e.g. some IDE), just point it to the correct python executable within the desired conda environment.

Solution 2:[2]

You have to add conda into PATH. Otherwise, conda and environment switches with command conda are only available within "Anaconda Prompt".

After adding conda in PATH, whic makes the command conda is available in every terminal, like cmd.exe, powershell.exe and "Anaconda Prompt".

"Anaconda Prompt" could be deemed as a wrapper of cmd.exe that does conda activate base for you automatically.

Solution 3:[3]

How do I use conda environments outside of the Anaconda Prompt?

Not sure if I get the "outside of Anaconda Prompt" correctly. But if you want to start the miniconda in say VScode's terminal, then the below method works for me.

If you don't want to add conda into PATH. The other way is to use the activation script in the miniconda folder to activate your venv.

  1. Look for your miniconda location.
    For example, my miniconda is located in C:\Users\User\miniconda3
  2. Navigate to ~\miniconda3\Scripts and copy the path of activate.bat (i.e, copy C:\Users\User\miniconda3\Scripts\activate.bat)
  3. Open a command prompt, paste, and execute the above bat file. Your miniconda should be activated, and you can use your conda command now.

This way you leave conda outside the PATH, but the downside is that you will need to do this everytime you want to activate your venv.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Pakhomov
Solution 2 Simba
Solution 3 Mike Chen