Ubuntu16.04安装caffe问题总结以及解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tanghong1996/article/details/81125043

th@th-Satellite-L40-A:~/caffe$ python
>>> import caffe

若不报错则表示 caffe 的 python 接口已正确编译
以下是我导入 caffe 时出现的错误:

1.No module named caffe

>>>import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named caffe

基本思路是把caffe中的python导入到解释器中

把环境变量路径放到 ~/.bashrc文件中,打开文件

sudo vim ~/.bashrc

不会用vim可以用

sudo gedit ~/.bashrc

在文件下方写入

export PATHONPATH=/home/xxx/caffe/python/caffe:$PATHONPATH
XXX为usrname

多个路径的话以冒号分隔,保存后输入:

source ~/.bashrc

th@th-Satellite-L40-A:~/caffe$ python
>>>import caffe
>>>

搞定

2.No module named google.protobuf.internal

th@th-Satellite-L40-A:~/caffe$ python
>>>import caffe
>>>“No module named google.protobuf.internal”

基本思路安装protobuf的包

pip install protobuf

或者

conda install protobuf

如果上述命令无法执行成功,可以尝试

sudo apt-get install python-protobuf

2.No module named skimage.io

解决方法:

pip install -U scikit-image

若没有安装pip

sudo apt install python-pip

3.安装依赖包问题

:~/caffe/python$ sudo pip install -r requirements.txt

输入上述命令,可能会出现如下情况

pandas 0.23.3 has requirement python-dateutil>=2.5.0, but you'll have python-dateutil 1.5 which is incompatible.
matplotlib 2.2.2 has requirement python-dateutil>=2.1, but you'll have python-dateutil 1.5 which is incompatible.
jupyter-client 5.2.3 has requirement python-dateutil>=2.1, but you'll have python-dateutil 1.5 which is incompatible.

但其实python-dateutil已经安装为2.7.3版本。

sudo gedit requirements.txt

将该句

python-dateutil>=1.4,<2

注释

#python-dateutil>=1.4,<2

然后
:~/caffe/python$ sudo pip install -r requirements.txt
搞定

猜你喜欢

转载自blog.csdn.net/tanghong1996/article/details/81125043
今日推荐