我用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'.
我怎么解决这个问题?非常感谢你。
更新 Caffe支持python 3.3+。请查看安装指南和prerequisites。
原始(过时)的答案 目前不支持在python 3中使用caffe:
Caffe的Python界面适用于Python 2.7。 Python 3或更早的Pythons是你自己的冒险。
现在可以为Python3构建Caffe了,我几乎可以肯定在问到这个问题时可能会在12月16日。
为此,您需要使用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
但是因此你只能在python3或python2中使用caffe,因为caffe的安装方式(使用PYTHON_PATH,确实不是一个好方法)。
要解决这个问题,你可以在你的〜/ .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"
因此两者都有效。
确保您使用的是RIGHT python版本。
import platform
print(platform.python_version())
我在Python3中遇到了这个问题,它在Python2中运行良好。