Importing caffe results in ImportError: “No module named google.protobuf.internal” (import enum_type_wrapper)

£可爱£侵袭症+ 提交于 2020-01-12 01:44:07

问题


I installed Anaconda Python on my machine. When I start the Python Interpreter and type "import caffe" in the Python shell, I get the following error:

ImportError: No module named google.protobuf.internal

I have the following files:

wire_format_lite_inl.h
wire_format_lite.h
wire_format.h
unknown_field_set.h
text_format.h
service.h
repeated_field.h
reflection_ops.h
message_lite.h
message.h
generated_message_util.h
extension_set.h
descriptor.proto
descriptor.h
generated_message_reflection.h
generated_enum_reflection.h
dynamic_message.h
descriptor.pb.h
descriptor_database.h

What files do I need so the import will work? Is there an "internal.h" file that is required?


回答1:


This is probably because you have two python environments in your machine, the one provided by your linux distribution(pip) and the other by the anaconda environment (/home/username/anaconda2/bin/pip).

Try installing protobuf for both environments to be sure

pip install protobuf

/home/username/anaconda2/bin/pip install protobuf




回答2:


If you are using Ubuntu, try installing protobuf using

sudo apt-get install protobuf

It solved the same problem that I faced.




回答3:


If you are using Anaconda, do conda install protobuf




回答4:


Easiest way to fix it:

pip install grpcio
pip install protobuf



回答5:


This is because the python envirnment confusion.

# check where pip2
$ where pip2
/usr/local/bin/pip2
/usr/bin/pip2

# check where pip
$ which pip
/usr/local/bin/pip

On my computer, I have two pip2(I install caffe using python2 env), so I used /usr/local/bin/pip2 install protobuf solved this problem.

/usr/local/bin/pip2 install protobuf


来源:https://stackoverflow.com/questions/37666241/importing-caffe-results-in-importerror-no-module-named-google-protobuf-interna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!