Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 712
user6726469 Avatar asked Oct 03 '16 08:10

user6726469


People also ask

Why is PyCharm not working in my terminal?

Note: be sure your terminal is not activating some environment by default. It is a common case with the base environment after Anaconda/Miniconda installation. If it fails with the same error as in PyCharm - the problem is most likely not related to PyCharm.

How to install a package in PyCharm?

You may as well copy the executed by PyCharm command from Run window, paste it to the terminal and run. Example of such command: - run pip install <package_name> or conda install <package_name> accordingly if you have problems installing a package in PyCharm;

How do I add a CSV file to PyCharm?

And how you can add the file permanently to your Pycharm directory. Note: install pandas first if not already installed. Find the CSV file path you want to import or read in Pycharm. To find the CSV file on your computer, type the filename in the “Type here to search” taskbar in windows. Find that at the bottom left of your computer screen.

How do I copy and paste a file in PyCharm?

Right-click on the file you want and click “Copy full path”. Or click the arrow-head shape in front of the file you want and click “Copy full path”. Open Pycharm and write the below three-line code: Remember to include “r” first inside the bracket.


1 Answers

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

like image 156
Erik Isusquiza Avatar answered Nov 11 '22 01:11

Erik Isusquiza