Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting PyCharm to recognize Anaconda's SciPy

I need to use the SciPy libraries inside the PyCharm IDE (on a Mac OSX Lion machine). The SciPy website writes that the simplest installation method for Mac users is to install Anaconda (or an equivalent distro). I used the Anaconda installer, and it created an anaconda directory in my home folder, where I find a lib/python2.7/site-packages directory with the required packages. However, PyCharm is not aware of all this and the SciPy import statements remain unresolved.

My question is then how to make PyCharm work with Anaconda?

like image 553
hillel Avatar asked Sep 21 '13 09:09

hillel


People also ask

How do I add a conda interpreter in PyCharm?

To create a Conda environmentClick the Python Interpreter selector and choose Add New Interpreter. Press Ctrl+Alt+S to open the project Settings/Preferences and go to Project: <project name> | Python Interpreter. Click the Add Interpreter link next to the list of the available interpreters.

How do I select an interpreter in PyCharm?

Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter. Expand the list of the available interpreters and click the Show All link. Select the target interpreter and click Edit. You can specify an alternative interpreter name for the selected interpreter.

How do you use Anaconda Python in PyCharm?

Step 1) In the Settings/Preferences dialog (⌘,), select Project: <project name> | Project Interpreter. step 2) In the left-hand pane of the Add Python Interpreter dialog box, select Conda Environment.


1 Answers

I'm still coming to terms with the Python ecosystem and PyCharm, so take the following with a grain of salt, but after reading up a bit, I thought I'd write a detailed explanation.

During installation, Anaconda changes the default Python interpreter to ~/anaconda/bin/python. This interpreter is configured with a sys.path that defaults to the libraries in ~/anaconda/lib . Package managers like python's pip use the interpreter that's running them to determine the path in which to install packages, so after Anaconda is installed, all packages installed via pip or other methods will be placed somewhere inside ~/anaconda/lib. i.e. even without using something like virtualenv, every Python interpreter has its own ecosystem and running pip with different interpreters will install packages into different directories.

PyCharm handles all this in the Project Settings-->Project Interpreter-->Python Interpreters screen. To make PyCharm aware of the Anaconda distribution, you need to add the Anaconda python interpreter to the Project Interpreter-->Python Interpreters list and make it the default for the project. PyCharm will then locate all packages installed in Anaconda's interpreter ecosystem (~/anaconda/lib) and list them under packages in the lower pane. It will also prompt you to install setup_tools and pip for that interpreter, and once you do that you'll be able to use the install button in the lower pane to add more packages to the Anaconda ecosystem.

Once you've added the Anaconda interpreter, you can also use the virtualenv button from the toolbar on the upper pane to create a virtualenv that inherits from the Anaconda interpreter's environment. That way you can install new packages in a way that would not affect the global Anaconda distribution.

like image 169
hillel Avatar answered Oct 02 '22 15:10

hillel