Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
805 views
in Technique[技术] by (71.8m points)

python - PyCharm terminal doesn't activate conda environment

I have a conda environment at the default location for windows, which is C:ProgramDataAnaconda2envsmyenv. Also, as recommended, the conda scripts and executables are not in the %PATH% environment variable. I opened a project in pycharm and pointed the python interpreter to C:ProgramDataAnaconda2envsmyenvpython.exe and pycharm seems to work well with the environment in the python console, in the run environment, and in debug mode.

However, when opening the terminal the environment is not activated (I made sure that the checkbox for activating the environment is checked). To be clear - when I do the same thing with a virtualenv the terminal does activate the environment without a problem.

Here are a few things I tried and did not work:

  • Copied the activate script from the anaconda folder to the environment folder
  • Copied the activate script from the anaconda folder to the Scripts folder under the environment
  • Copied an activate script from the virtualenv (an identical one for which the environment is activated)
  • Added the anaconda folders to the path

None of these worked. I can manually activate the environment without a problem once the terminal is open, but how do I do it automatically?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I ran into the same problem and used this solution.

  1. Go to File -> Settings -> Tools -> Terminal.

  2. Replace the value in Shell path with cmd.exe "/K" C:pathoAnaconda3Scriptsactivate.bat your_environment_name.

If I installed Anaconda in C:Anaconda3 and have an environment named myenv, then my settings would look like this:

Terminal Tool Application settings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...