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
搞定