17

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?

hillel
  • 2,343
  • 2
  • 18
  • 25
  • Did you run the installation correctly? Did you say 'yes' when it asked you if it can modify `.bashrc`? – Rohit Sep 21 '13 at 10:12
  • @Rohit In OSX it's .bash_profile, but yes, the installer changed it (added anaconda/bin to the PATH variable). – hillel Sep 21 '13 at 10:16
  • Yes. Sorry. That is useful only for the built-in interpreter. – Rohit Sep 21 '13 at 10:21
  • 1
    I'm sure you've looked at this, but nevertheless, http://www.jetbrains.com/pycharm/webhelp/installing-uninstalling-and-upgrading-packages.html – Rohit Sep 21 '13 at 10:22
  • 1
    @Rohit your link explains the procedure of adding individual packages, but it also pointed me toward a workaround to use Anaconda: navigate to preferences-->Project Interpreter-->Python Interpreters and then in the lower pane choose Paths and add anaconda/lib/python2.7/site-packages. It seems to be working for now (at least for SciPy), but if anyone knows of a more formal method, add an answer and I'll select it. – hillel Sep 21 '13 at 10:35

1 Answers1

37

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.

Joe
  • 3,370
  • 4
  • 33
  • 56
hillel
  • 2,343
  • 2
  • 18
  • 25
  • 5
    How do you get the virtualenv to inherit from Anaconda? – Arash Saidi Oct 23 '14 at 15:12
  • Pycharm just goes nuts and has to be forcibly shutdown if you start a jupyter notebook. It can't find the notebook url. I also couldn't find this virtualenv toolbar. I am using the paid version (but I do Java mostly so not a total loss) – Abhishek Dujari Nov 12 '17 at 15:30