相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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

is there a way to set the environment of the current interpreter as the starting environment (say instead of base)? – stats-hb Nov 15, 2018 at 16:15 @ML_Pro you may have to modify the rc file or specify a new one on linux, get more infomation here – dd. Nov 20, 2018 at 0:48 Anyone knows how to use Anaconda Powershell Prompt within PyCharm? I've simply copy&pasted the command from the Anconda Powershell shortcut found under 'target'. It is working with Windows/Run but in PyCharm I get Cannot open Local Terminal Failed to start [C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe --ExecutionPolicy ByPass --NoExit --Command (...COMMAND...)] – Bibonaut Mar 17, 2020 at 13:33

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

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

  • right click 'anaconda powershell prompt' in the start menu; click 'open file location'
  • right click 'anaconda powershell prompt' in file explorer; click 'properties'
  • 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' "
    
  • go to pycharm under settings -> tools -> Terminal
  • 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)

  • restart the terminal in pycharm and you should be in the base conda environment
  • 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:

  • 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
  • Then go to Settings - Tools - Terminal
  • 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.

    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
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

     
    推荐文章