Nicholas
Nicholas

Reputation: 576

Get the Anaconda prompt running in the PyCharm terminal

I have Miniconda3 installed at C:\Users\me\Miniconda3, and my 'Project Interpreter' within PyCharm set to my conda environment, and that is all working correctly. However it appears that conda is not set for my path variable as if I type conda into the PyCharm Terminal I get

'conda' is not recognized as an internal or external command, operable program or batch file.

Is there a way to set the PyCharm Terminal to behave like the Anaconda Prompt?

I have Windows 10, PyCharm 2018.1 EAP, and conda 4.4.10 installed.

Upvotes: 29

Views: 31473

Answers (7)

ZKS
ZKS

Reputation: 2836

In case you are using Miniconda , Windows 11 and Pycharm Community Edition

enter image description here

In Shell Path set below path replacing you respective user id

cmd.exe "/K"     
C:\Users\your_user_Id\AppData\Local\miniconda3\Scripts\activate.bat 
C:\Users\your_uesr_id\AppData\Local\miniconda3

Upvotes: 3

tCot
tCot

Reputation: 357

Type in Anaconda Prompt conda env list to retrieve the conda path. Move to the folder with your bash (eg : GitBash):

cd <conda path>/etc/profile.d

And add conda to the ~/.basrc file :

echo ". ${PWD}/conda.sh" >> ~/.bashrc

Activate the modifications of your ~/.basrc :

source ~/.bashrc

Upvotes: 0

basil_man
basil_man

Reputation: 604

Here's what I got to work (its a variation of dd. post):

  1. right click 'anaconda powershell prompt' in the start menu; click 'open file location'
  2. right click 'anaconda powershell prompt' in file explorer; click 'properties'
  3. under 'shortcut' tab the 'target' line is what you need. mine looked like
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\ProgramData\Anaconda3' "
  1. go to pycharm under settings -> tools -> Terminal
  2. leave the current powershell path (don't change it!), and append on:
 -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\ProgramData\Anaconda3' "

(this is part of the path above)

In fact, the full version can be written directly as

powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\ProgramData\Anaconda3' "

No need to explicitly specify the path to powershell. (Still need to replace the path to anaconda with your own.)

(also make sure there is a space between the end of the powershell path and the dash)

  1. restart the terminal in pycharm and you should be in the base conda environment

Upvotes: 1

Luk Aron
Luk Aron

Reputation: 1415

For window user, first of all check the location of your anaconda environment

you could type conda env list to show

For my case, the env I want to have my anaconda prompt is located at C:\Users\YOURUSERNAME\Anaconda3\ (which is the root env, the very first you get)

And then go to pycharm, go settings, go Tools, Inside Shell path enter

cmd.exe "/K" C:\Users\YOURUSERNAME\Anaconda3\Scripts\activate.bat C:\Users\YOURUSERNAME\Anaconda3

Upvotes: 9

Fhyarnir
Fhyarnir

Reputation: 473

Great answer by dd. It helped me out as well, but I chose to do it in a slightly different way in PyCharm.

It appears we can get the Anaconda prompt running in the PyCharm terminal without having to redirect to a new Shell path, ie. we may keep the original Shell path which in my case is "C:\Windows\System32\cmd.exe" for Windows 10. And instead point to the Environment Variables that are used by the conda command prompt, in the following way:

  1. Get the PATH value of your conda environment, for instance by performing echo %PATH from the conda command prompt as described here in the answer by Rob / Adrian. If you have already set the PATH for the python interpreter in PyCharm you can find it here: Settings - Build, Execution, Deployment - Console - Python Console. Click the folder button to the right of Environment variables input and then copy the path value from the Value field to the right of the variable under Name
  2. Then go to Settings - Tools - Terminal
  3. Click the folder icon to the right of Environment Variables input section, and create a new variable by pressing the + symbol. Name it PATH and paste in the previously copied value. Click OK and then Apply

You could restart PyCharm, or close and restart Terminal within PyCharm, in order to make sure the changes have been recognized.

Now you should be able to use for instance both pip list and conda list within the same Terminal window within PyCharm. In my case the former command returns a smaller list compared to the larger list from the other command (from conda).

Regardless, it appears you should now be able to use both within one, ie. to use the same Terminal window to perform conda and regular python operations, for instance for installations.

Sidenote: Though the two-in-one option works for the Terminal windows it does not seem to work for the Python Console - where I use the conda one within PyCharm. In that Console it currently only recognize packages from the conda interpreter and not the packages from my previous regular python interpreter.

Anyway, hope this helps other people! If anyone has any insights into whether or not this is a viable solution in the long run, please let me know.

Upvotes: 0

sonictl
sonictl

Reputation: 63

The shell path may differ, you can check from the properties of shortcut of 'Anaconda Prompt': rightClick on the icon of 'Anaconda Prompt' >> properties >> shortcut >> Target

Upvotes: 3

dd.
dd.

Reputation: 866

You can change pycharm settings to achieve this.

In Settings > Tools > Terminal, change the Shell path as following:

cmd.exe "/K" "C:\Users\me\Miniconda3\Scripts\activate.bat" "C:\Users\me\Miniconda3"

And the C:\Users\me\Miniconda3 can be replaced by either one of your conda environment name such as base

Close the Terminal and reopen it, you will get the Anaconda prompt.

It works in my PyCharm Community Edition 2018.1.2

Upvotes: 58

Related Questions