ImportError: dynamic module does not define module export function (PyInit__caffe)
ImportError: dynamic module does not define module export function (PyInit__caffe)
我用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)
但它在 python2.7.
中运行良好
我已经将 /path/to/caffe/distrubute/python 添加到 PATH,但是当我制作 pycaffe 时,它显示
make: Nothing to be done for `pycaffe'.
我该如何解决这个问题?
非常感谢。
更新
Caffe 支持 python 3.3+。
请查看安装指南和 prerequisites.
原始(过时)答案
当前不支持将 caffe 与 python 3 一起使用:
Caffe’s Python interface works with Python 2.7. Python 3 or earlier Pythons are your own adventure.
现在可以为 Python3 构建 Caffe,而且我几乎可以肯定在 12 月 16 日提出问题时它是可能的。
为此,您需要删除 Makefile.config 和 Python3 中的注释:
# 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"
因此两者都可以。
确保您使用的是正确的 python 版本。
import platform
print(platform.python_version())
我在 Python3 中遇到了这个问题,在 Python2 中它工作正常。
我用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)
但它在 python2.7.
中运行良好我已经将 /path/to/caffe/distrubute/python 添加到 PATH,但是当我制作 pycaffe 时,它显示
make: Nothing to be done for `pycaffe'.
我该如何解决这个问题? 非常感谢。
更新
Caffe 支持 python 3.3+。
请查看安装指南和 prerequisites.
原始(过时)答案
当前不支持将 caffe 与 python 3 一起使用:
Caffe’s Python interface works with Python 2.7. Python 3 or earlier Pythons are your own adventure.
现在可以为 Python3 构建 Caffe,而且我几乎可以肯定在 12 月 16 日提出问题时它是可能的。
为此,您需要删除 Makefile.config 和 Python3 中的注释:
# 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"
因此两者都可以。
确保您使用的是正确的 python 版本。
import platform
print(platform.python_version())
我在 Python3 中遇到了这个问题,在 Python2 中它工作正常。