【问题标题】:ImportError: dynamic module does not define module export function (PyInit__caffe)ImportError:动态模块没有定义模块导出函数(PyInit__caffe)
【发布时间】:2016-03-21 14:13:21
【问题描述】:

我用 python3 安装 caffe,但是当我导入 caffe 时,我得到了一些错误 Traceback(最近一次调用最后一次):

 File "classify.py", line 14, in <module>
    import caffe
  File "/home/hez/caffe-master/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver
  File "/home/hez/caffe-master/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver
ImportError: dynamic module does not define module export function (PyInit__caffe)

但它在python2.7中运行良好。

我已将 /path/to/caffe/distrubute/python 添加到 PATH,但是当我制作 pycaffe 时,它​​显示了

make: Nothing to be done for `pycaffe'.

我该如何解决这个问题? 非常感谢。

【问题讨论】:

  • 您现在也可以在CMakeLists.txt文件中将python版本从2改为3。

标签: python neural-network deep-learning caffe


【解决方案1】:

确保您使用的是正确的 python 版本。

import platform
print(platform.python_version())

我在 Python3 中遇到了这个问题,它在 Python2 中运行良好。

【讨论】:

  • 如果您使用正确的 python 版本重建模块,您必须退出解释器,然后再尝试以交互方式再次导入模块。否则,python 将继续打印相同的错误,即使文件现在是正确的。
【解决方案2】:

更新
Caffe 支持 python 3.3+。 请查看安装指南和prerequisites

原始(过时)答案
目前不支持在 python 3 中使用 caffe:

Caffe 的 Python 界面适用于 Python 2.7。 Python 3 或更早版本的 Python 是您自己的冒险。

caffe's installation tutorial

【讨论】:

  • 嘿,还是这样吗? caffe 安装说明也显示了 python3。您能否根据新信息更新您的答案
【解决方案3】:

现在可以为 Python3 构建 Caffe,我几乎可以肯定,在 12 月 16 日提出问题时,它是可能的。

为此,您需要使用 Python3 删除 Makefile.config 中的 cmets:

# Uncomment to use Python 3 (default is Python 2)
# Check that boost library name is correct here!!!
PYTHON_LIBRARIES := boost_python3 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5m \
                 /usr/lib/python3.5/dist-packages/numpy/core/include

但是由于 caffe 的安装方式(使用 PYTHON_PATH,确实不是一个好方法),因此您只能在 python3 或 python2 中使用 caffe。

要解决此问题,您可以在 ~/.bashrc 中执行此操作:

alias python2="export PYTHONPATH=$PYTHONPATH:/home/undead/reps/caffe_py2/python && python2"
alias python3="export PYTHONPATH=$PYTHONPATH:/home/undead/reps/caffe_py3/python && python3"
alias python="export PYTHONPATH=$PYTHONPATH:/home/undead/reps/caffe_py2/python && python2"

因此两者都会起作用。

【讨论】:

  • 进行这些更改后是否需要“全部制作”?
  • @Ravikrn 不,您需要构建两个库 (.so) 并以这种方式指向它们。
  • 能否详细说明。我只想要python3,最初我用python2指令安装了caffe。构建两个库是什么意思?我的 ~/.bashrc 有“export PYTHONPATH=/home/path/caffe/python:$PYTHONPATH”
  • @Ravikrn 在您的情况下,您只需要使用 python3 重建 caffe。但是之后python2 caffe 就会丢失。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-23
  • 2016-12-30
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 2020-10-27
相关资源
最近更新 更多