【问题标题】:Error on import caffe导入caffe时出错
【发布时间】:2016-02-17 15:53:52
【问题描述】:

DeepDream或其他深度学习项目,搭建Caffe环境。

我为 PyCaffe 安装了所需的包,并将 PYTHONPATH 设置为 caffe/python。

但是当我在 python 上导入 caffe 时:

import caffe

出现如下错误。如何解决这个问题?

Segmentation fault: 11

【问题讨论】:

  • 感谢您的推荐。但是这次我坚持使用 Caffe,而不是 openCV,并且我使用 Python 2.7.10。我认为我的问题与您提到的不同。
  • 您是否尝试过该链接上建议的解决方案?
  • 是的,我按照该链接的建议尝试了“sudo python”和“import caffe”,但随后出现错误“ImportError: No module named caffe”。

标签: python machine-learning caffe pycaffe


【解决方案1】:

你用的是mac吗?我很难在 mac 上制作 pycaffe,直到我意识到所有 mac 上都安装了本机 python,并且我使用的是我安装的另一个版本。在编译时,caffe 使用了本机 python 中的一些东西,以及其他 python 中的一些东西。我必须确保更改 makefile.config 文件中的所有相关路径并更改我的 bash 使用的 python。我也建议在虚拟环境中工作。 This 是一个很好的链接来帮助你,祝你好运!

【讨论】:

    【解决方案2】:

    自 2015 年以来,Github issue 已对此进行了讨论。 主要原因是自制python和OS X系统python冲突。

    Homebrew 提供了一个awesome solution for OS X:

    $ python -V   # system Python interpreter
    $ python2 -V  # Homebrew installed Python 2 interpreter
    $ python3 -V  # Homebrew installed Python 3 interpreter (if installed)
    

    所以解决方案是将所有 python 路径更改为 python2。咆哮是我的 Makefile.config 相关:

    # ...
    # NOTE: this is required only if you will compile the python interface.
    # We need to be able to find Python.h and numpy/arrayobject.h.
    # PYTHON_INCLUDE := /usr/include/python2.7 \
    #       /usr/lib/python2.7/dist-packages/numpy/core/include
    # ------ For Homebrew installed python. Numpy path is added using python commands. 
    PYTHON_INCLUDE := /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/include/python2.7
    
    # We need to be able to find libpythonX.X.so or .dylib. ------ (Update Homebrew path)
    # PYTHON_LIB := /usr/lib
    # PYTHON_LIB := $(ANACONDA_HOME)/lib
    PYTHON_LIB := /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib
    
    # Homebrew installs numpy in a non standard path (keg only) ------ (python2 for brew instead of python for system)
    PYTHON_INCLUDE += $(dir $(shell python2 -c 'import numpy.core; print(numpy.core.__file__)'))/include
    PYTHON_LIB += $(shell brew --prefix numpy)/lib
    # ...
    

    【讨论】:

      【解决方案3】:

      如果没有出现名为 caffe 的模块错误,请尝试在 python 脚本中手动设置 python 路径

      例如。 导入系统

      sys.path.insert(0, "/home/nviso/GitHub/caffe/distribute/python")

      导入咖啡

      这通常对我有用。 手动将 caffe 或 python 路径添加到 .bashrc 应该也可以解决问题,虽然不确定,现在没有我的 Office PC 可以尝试:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-24
        • 1970-01-01
        • 1970-01-01
        • 2017-07-13
        • 2015-11-09
        • 2020-12-11
        相关资源
        最近更新 更多