ChatGPT解决这个技术问题 Extra ChatGPT

Using (Ana)conda within PyCharm

I've got Pycharm 4 running on my Linux (Ubuntu 14.04) machine. In addition to the system python, I've also got Anaconda installed. Getting the two to play nicely together seems to be a bit of a problem... PyCharm provides some interesting integration for virtualenvs and pip, but the Anaconda Python distribution seems to prefer using its own conda tool for both activities.

Is there a relatively simple/painless way to be able to use conda in conjunction with PyCharm? Not just as an alternative interpreter i.e. point PyCharm at the Anaconda Python binary for a project interpreter, but to be able to create, source/activate and deactivate virtual envs, add/remove packages in those virtual envs, etc.

Or am I going to have to choose between using Anaconda (and having a more recent and up-to-date python than may come with the system), and being able to use PyCharm's features to their fullest extent?

This may answer at least part of your question stackoverflow.com/a/19025207/161801
Not really... getting PyCharm to see/use the Anaconda Python interpreter, or an interpreter from a virtualenv created using conda, is not a problem. Getting PyCharm to use conda to manage or recognize packages or virutalenvs created using conda, is.
I see. I don't think there is a way yet, but you can vote on the feature here youtrack.jetbrains.com/issue/PY-13698
I had problems in getting PyCharm to find installed packages after starting to use Conda, on an Ubuntu (14.04 and later 16.04) with PyCharm 4.5. The problem seems to be that if I have open projects in PyCharm that use a normal virtualenv, then the open projects with Conda won't find installed packages. If I close the projects that do not use Conda, then the Conda projects find the packages as they should.

c
cyberbikepunk

I know it's late, but I thought it would be nice to clarify things: PyCharm and Conda and pip work well together.

The short answer

Just manage Conda from the command line. PyCharm will automatically notice changes once they happen, just like it does with pip.

The long answer

Create a new Conda environment:

conda create --name foo pandas bokeh

This environment lives under conda_root/envs/foo. Your python interpreter is conda_root/envs/foo/bin/pythonX.X and your all your site-packages are in conda_root/envs/foo/lib/pythonX.X/site-packages. This is same directory structure as in a pip virtual environement. PyCharm sees no difference.

Now to activate your new environment from PyCharm go to file > settings > project > interpreter, select Add local in the project interpreter field (the little gear wheel) and hunt down your python interpreter. Congratulations! You now have a Conda environment with pandas and bokeh!

Now install more packages:

conda install scikit-learn

OK... go back to your interpreter in settings. Magically, PyCharm now sees scikit-learn!

And the reverse is also true, i.e. when you pip install another package in PyCharm, Conda will automatically notice. Say you've installed requests. Now list the Conda packages in your current environment:

conda list

The list now includes requests and Conda has correctly detected (3rd column) that it was installed with pip.

Conclusion

This is definitely good news for people like myself who are trying to get away from the pip/virtualenv installation problems when packages are not pure python.

NB: I run PyCharm pro edition 4.5.3 on Linux. For Windows users, replace in command line with in the GUI (and forward slashes with backslashes). There's no reason it shouldn't work for you too.

EDIT: PyCharm5 is out with Conda support! In the community edition too.


sorry but I really can't help with windows. I never use it and I'm not knowledgeable.
pycharm will mistakenly think you didn't install any package if you write them in requirements.txt even when they are installed into the right path "~/anaconda/lib/python2.7/site-packages", and the program is runnable when you click run
This answer was most useful in adding some confidence for me because it can be confusing for people like me coming from text editors. I have the pro edition as well and I am happy to know its more helpful that the bass ackward thing I had to deal with on windows since 2006. I also recommend looking at the answer from @Piotr-czapla for the conda environment. I totally avoid Windows CMD prompt when I can. It was trendy in 1998
TLDR; On Windows your local python for environment is in conda_root/envs/foo/python.exe
What if you don't have an executable (python.exe) inside your environment folder?
B
BullyWiiPlaza

Change the project interpreter to ~/anaconda2/python/bin by going to File -> Settings -> Project -> Project Interpreter. Also update the run configuration to use the project default Python interpreter via Run -> Edit Configurations. This makes PyCharm use Anaconda instead of the default Python interpreter under usr/bin/python27.


P
Piotr Czapla

as per @cyberbikepunk answer pycharm supports Anaconda since pycharm5!

https://i.stack.imgur.com/c4oE5.png


S
SpeedCoder5

Continuum Analytics now provides instructions on how to setup Anaconda with various IDEs including Pycharm here. However, with Pycharm 5.0.1 running on Unbuntu 15.10 Project Interpreter settings were found via the File | Settings and then under the Project branch of the treeview on the Settings dialog.


n
noviceprogrammer

this might be repetitive. I was trying to use pycharm to run flask - had anaconda 3, pycharm 2019.1.1 and windows 10. Created a new conda environment - it threw errors. Followed these steps -

Used the cmd to install python and flask after creating environment as suggested above. Followed this answer. As suggested above, went to Run -> Edit Configurations and changed the environment there as well as in (2).

Obviously kept the correct python interpreter (the one in the environment) everywhere.