我无法在pycharm中导入caffe,但我可以在终端导入。为什么?

时间:2016-10-03 08:20:25

标签: python pycharm caffe

我想导入caffe。我可以在终端导入它,但不能在pycharm中导入。

我尝试了一些建议,例如将include /usr/local/cuda-7.0/lib64添加到/user/etc/ld.so.conf文件,但仍无法导入此模块。但是,我认为这不是一个好的解决方案,因为我只使用CPU模式。

enter image description here

我正在使用linux mint。

pycharm终端中sys.path的输出是:

>>> 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']
>>> 

当我在pycharm中运行sys.path时,我得到:

 ['/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/']

与我在终端中运行它的时间不完全相同。

此外,当我在pycharm中运行import caffe时,错误如下:

/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
你可以帮我吗?

4 个答案:

答案 0 :(得分:3)

我也使用pycharm终端安装了caffe,但它没有用。最后我将sys.path.extend([/home/user/caffe-master/python])添加到python consule,同时我在我的代码中写了以下内容。

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

它工作了!!!

答案 1 :(得分:3)

您需要在解释器路径下添加相同的路径。 设置 - &gt;项目口译员 - &gt;点击口译员旁边的齿轮 - &gt;更多 - &gt;点击显示&#39;显示解释器路径的图标&#39; - &GT;添加路径 - &gt;混乱解决了。

答案 2 :(得分:2)

这个解决方案对我有用。我认为问题是pycharm不会从bashrc中收取库。

  1. 打开Pycharm
  2. 转到文件 - &gt;设置 - &gt;项目口译员
  3. enter image description here

    1. 用所有可能的口译员打开栏,然后按show all。
    2. enter image description here

      1. 单击选项的最后一个按钮(棕色底部)。

      2. 添加python路径(/ home / user / caffe / python)

      3. enter image description here

答案 3 :(得分:0)

我通过在项目解释器中添加caffe解决了这个问题。只需使用右侧的+即可获得可用包列表。搜索caffe并单击Install Package。

相关问题