(原)python中import caffe提示no module named google.protobuf.internal

轉載請註明出處:html

http://www.cnblogs.com/darkknightzh/p/5993405.htmlpython

以前在一臺臺式機上在python中使用import caffe時,沒有出錯。可是在服務器上使用import caffe時,提示no module named google.protobuf.internal。bash

在protobuf-2.6.1的文件夾內,有python文件夾的README.txt裏面寫了怎麼安裝python的支持。服務器

1. 終端定位到protobuf-2.6.1/python中,而後輸入:python2.7

python setup.py build

安裝完以後,就能夠了。ui

若是繼續輸入google

python setup.py google_test

可能會有錯誤:spa

raise exceptions.UnparsedFlagAccessError(error_message)code

貌似不用管吧。終端中繼續輸入htm

python
import caffe

不會提示no module named google.protobuf.internal了。

2. 若是到此處,只有當終端在protobuf-2.6.1/python目錄內時,python中import caffe纔不會報錯。當終端在其餘文件夾內時,import caffe依舊會出錯。在終端中輸入以下命令:

export PYTHONPATH=/home/XXX/protobuf-2.6.1/python:$PYTHONPATH

以後輸入:

source ~/.bashrc

後,在其餘文件夾內使用python時,import caffe便不會出錯了。

說明:

剛纔查了一下,臺式機上python是默認的/usr/lib/python2.7,而服務器上是在其餘路徑下的miniconda2。可能這個緣由,致使服務器上直接編譯protobuf後,在使用時,因爲python路徑不對,出錯了吧(瞎猜的)。。。

相關文章
相關標籤/搜索