1.更改Makefile.config文件的配置如下,该配置默认python2.7,把2.7注释掉,3.5解注释
#PYTHON_INCLUDE := /usr/include/python2.7 \
# /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
# $(ANACONDA_HOME)/include/python2.7 \
# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python3 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5m \
/usr/lib/python3.5/dist-packages/numpy/core/include
2.运行:
sudo make all -j12
sudo make pycaffe
sudo make test -j12
成功后,进入python3.5.2下import caffe出现以下错误:
ImportError: No module named _caffe
解决:
先:
gedit~/.bashrc
加入:
export PATHONPATH=/home/xxx/caffe/python/caffe:$PATHONPATH
最后:
$ source~/.bashrc
3.make clean之后重新再make一边(同上),成功,但是进入python3.5.2下import caffe出现以下错误:
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xxx/caffe/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/home/xxx/caffe/python/caffe/pycaffe.py", line 13, in <module>
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: /home/xxx/caffe/python/caffe/_caffe.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
原因:
libboost_python.so的版本不匹配,默认python版本为3.5,而boost_python为2.7。
解决:
将:
PYTHON_LIBRARIES := boost_python3 python3.5m
改为:
PYTHON_LIBRARIES := boost_python-py35 python3.5m
重新编译即可:
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>>