My default Python binary is set to the one with the Anaconda distribution of Python. This is found at /home/karnivaurus/anaconda/bin/python, and I have made this the default by adding to my .bashrc file the following: export PATH=/home/karnivaurus/anaconda/bin:$PATH.

I also have a Python package called caffe, which is located at /home/karnivaurus/caffe/distribute/python, and I have added this to the package search path by adding to my .bashrc file the following: export PYTHONPATH=${PYTHONPATH}:/home/karnivaurus/caffe/distribute/python.

Now, I have a simple Python file, called test.py, with the following contents:

import caffe
print "Done."

If I run this by entering python test.py into the terminal, it runs fine, printing out "Done.". The problem I am having is when I run this in the PyCharm IDE. In PyCharm, I have set the interpreter to be /home/karnivaurus/anaconda/bin/python. But when I open test.py in PyCharm, and run the file in the IDE, I get the following error:

ImportError: No module named caffe

So my question is: Why can PyCharm not find the caffe module when it runs the Python script, but it can be found when I run the script from the terminal?

Thank you!

  • 2
    I guess PyCharm does not care about your .bashrc, as that's a bash-specific config file. You have to set that variable either in PyCharm or in e.g. .profile – Byte Commander Oct 12 '15 at 12:12

As ByteCommander said in a comment, PyCharm doesn't use bashrc, so it doesn't know where your library is.

In the same screen where you added the interpreter you can see a wheel icon, click it, it will show you a menu, click on more. You should see a screen like this:

PyCharm Interpreter configuration

You should select your interpreter and click on the last button. This should open this window:

Interpreter paths configuration

Now clicking on the plus icon you should be able to add your own paths for libraries.

  • 2
    And this is a good example about why giving instructions is easier with command line than GUIs. – Javier Rivera Oct 14 '15 at 6:52
  • Thanks. Is this the way to add paths for both binary libraries, and Python modules? Or should Python modules be added to the "Source Root"? – Karnivaurus Oct 14 '15 at 10:02
  • 1
    Both. You should only use Source Root if you are going to make changes to that modules (you don't need to add then to Source Root for completion, documentation or 'going to source' to work). – Javier Rivera Oct 14 '15 at 10:43

Programs started from the Ubuntu launcher do not read .bashrc. As an alternative to setting the paths in PyCharm, you can simply start PyCharm from a Bash shell to give it access to the environment variables you set in .bashrc.

  • Is there a way to make programs read .bash_rc file when started from launcher? – User007 Oct 30 '17 at 22:30

Open the following shortcut (Ctrl + Alt + S), and click (Project: xxxx), now choose (Project Structure) and select (/home/yourUser/PycharmProjects/XXXX/venv/bin) and right-click (Excluded) or (Alt + E).

Now click (+ Add Content Root) and see if it points to the following location (/home/ yourUser/PycharmProjects/XXXXX/venv/bin) and click OK. Now close the IDE and open it again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.