Python 导入错误:动态模块没有定义模块导出功能(PyInit__caffe)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34295136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: dynamic module does not define module export function (PyInit__caffe)
提问by Philokey
I install caffe with python3,but when I import caffe, I get some errors Traceback (most recent call last):
我用python3安装了caffe,但是当我导入caffe时,出现了一些错误回溯(最近一次调用):
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)
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)
But it work well in python2.7.
但它在python2.7中运行良好。
I had add /path/to/caffe/distrubute/python to the PATH, but when I make pycaffe, it shows that
我已经将 /path/to/caffe/distrubute/python 添加到 PATH,但是当我制作 pycaffe 时,它表明
make: Nothing to be done for `pycaffe'.
How can I solve this problem? Thank you very much.
我怎么解决这个问题?非常感谢。
采纳答案by Shai
Update
Caffe supports python 3.3+.
Please checkout installation guide and prerequisites.
更新
Caffe 支持 python 3.3+。请检查安装指南和先决条件。
Original (outdated) answer
Using caffe with python 3 is not currently supported:
当前不支持在 python 3 中使用 caffe 的原始(过时)答案:
Caffe's Python interface works with Python 2.7. Python 3 or earlier Pythons are your own adventure.
Caffe 的 Python 接口适用于 Python 2.7。Python 3 或更早版本的 Python 是您自己的冒险。
See caffe's installation tutorial.
参见caffe的安装教程。
回答by UndeadDragon
It is now possible to build Caffe for Python3, and I'm almost sure it was possible in December 16 when the question was asked.
现在可以为 Python3 构建 Caffe,我几乎可以肯定在 12 月 16 日提出这个问题时是可能的。
To do this, you need to remove the comments in the Makefile.config with Python3:
为此,您需要使用 Python3 删除 Makefile.config 中的注释:
# 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
But therefore you will have caffe only in python3 OR python2, because of the way how caffe installs (with PYTHON_PATH, not a good way indeed).
但是因此您只能在 python3 或 python2 中使用 caffe,因为 caffe 的安装方式(使用 PYTHON_PATH,确实不是一个好方法)。
To workaround this, you can do such trick in your ~/.bashrc:
要解决此问题,您可以在 ~/.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"
Therefore both will works.
因此两者都会起作用。
回答by FantasyJXF
make sure you are using the RIGHT python version.
确保您使用的是正确的 python 版本。
import platform
print(platform.python_version())
I met the problem in Python3, and it worked Okay with Python2.
我在 Python3 中遇到了这个问题,它在 Python2 中运行良好。