user6726469
user6726469

Reputation: 229

Why can I not import Caffe in PyCharm but can import it in terminal?

I want to import Caffe. I can import it in terminal but not in PyCharm.

I have tried some suggestions like adding include /usr/local/cuda-7.0/lib64 to /user/etc/ld.so.conf file but still it can not import this module. However, I think this is not a good solution as I am using the CPU mode only.

enter image description here

I am using Linux Mint.

The output for sys.path in PyCharm terminal is:

>>> sys.path
['', 
'/home/user/anaconda2/lib/python27.zip', 
'/home/user/anaconda2/lib/python2.7', 
'/home/user/anaconda2/lib/python2.7/plat-linux2', 
'/home/user/anaconda2/lib/python2.7/lib-tk', 
'/home/user/anaconda2/lib/python2.7/lib-old', 
'/home/user/anaconda2/lib/python2.7/lib-dynload', 
'/home/user/anaconda2/lib/python2.7/site-packages', 
'/home/user/anaconda2/lib/python2.7/site-packages/Sphinx-1.4.1-y2.7.egg',
'/home/user/anaconda2/lib/python2.7/site-packages/setuptools-23.0.0-py2.7.egg']
>>> 

and when I run sys.path in PyCharm itself, I get:

['/opt/pycharm-community-2016.2.3/helpers/pydev',
'/home/user/',
'/opt/pycharm-community-2016.2.3/helpers/pydev',
'/home/user/anaconda2/lib/python27.zip',
'/home/user/anaconda2/lib/python2.7',
'/home/user/anaconda2/lib/python2.7/plat-linux2',
'/home/user/anaconda2/lib/python2.7/lib-tk',
'/home/user/anaconda2/lib/python2.7/lib-old',
'/home/user/anaconda2/lib/python2.7/lib-dynload',
'/home/user/anaconda2/lib/python2.7/site-packages',
'/home/user/anaconda2/lib/python2.7/site-packages/Sphinx-1.4.1-py2.7.egg',
'/home/user/anaconda2/lib/python2.7/site-packages/setuptools-23.0.0-py2.7.egg',
'/home/user/anaconda2/lib/python2.7/site-packages/IPython/extensions',
'/home/user/']

which is not exactly the same as the time I ran it in terminal.

moreover, as I run the import caffe in PyCharm the error is as bellow:

/home/user/anaconda2/bin/python /home/user/important_commands.py
Traceback (most recent call last):
  File "/home/user/important_commands.py", line 11, in <module>
    import caffe
ImportError: No module named caffe

Process finished with exit code 1

Upvotes: 5

Views: 5064

Answers (4)

Christian Frick
Christian Frick

Reputation: 33

I solved the problem by adding caffe in the project interpreter. Just use the + on the right side for the list of available packages. Search for caffe and click on Install Package.

Upvotes: 0

Erik Isusquiza
Erik Isusquiza

Reputation: 83

This solution worked for me. I think that the problem is that pycharm doesn´t charge the libraries from the bashrc.

  1. Open Pycharm
  2. Go to File --> settings --> project interpreter

enter image description here

  1. Open the bar with all the possible interpreters and press show all.

enter image description here

  1. Click the last button of the options (Brown bottom).

  2. Add the python path (/home/user/caffe/python)

enter image description here

Upvotes: 4

Kevin Roy
Kevin Roy

Reputation: 111

You need to add this same path under you interpreters path. Settings -> Project interpreter ->click the cogwheel next to interpreter -> More -> click on icon that says 'Show paths for interpreter' -> add path -> Chaos Solved.

Upvotes: 3

user6726469
user6726469

Reputation: 229

I installed caffe using pycharm terminal too but it did not work. Finally I added sys.path.extend([/home/user/caffe-master/python]) to python consule and meanwhile I wrote the following in my code.

 import sys
 sys.path.append("/home/user/caffe-master/python/")
 import caffe

and it worked!!!

Upvotes: 3

Related Questions