No module named google.protobuf

不羁岁月 提交于 2019-11-28 09:01:49
Panfeng Li

There is another possibility, if you are running a python 2.7.11 or other similar versions,

sudo pip install protobuf

is ok.

But if you are in a anaconda environment, you should use

conda install protobuf

Locating the google directory in the site-packages directory (for the proper latter directory, of course) and manually creating an (empty) __init__.py resolved this issue for me.

(Note that within this directory is the protobuf directory but my installation of Python 2.7 did not accept the new-style packages so the __init__.py was required, even if empty, to identify the folder as a package folder.)

...In case this helps anyone in the future.

In my case I

  1. downloaded the source code, compiled and installed:

    $ ./configure
    $ make
    $ make check
    $ sudo make install`
    
  2. for python I located its folder(python) under source code, and ran commands:

    $ python setup.py build
    $ python setup.py install'
    

Not sure if this could help you..

I got the same error message when I tried to use Tensor Flow. The solution was simply to uninstall Tensor Flow and protobuf:

$ sudo pip uninstall protobuf
$ sudo pip uninstall tensorflow

And reinstall it again: pip installation of Tensorflow. Currently, this is:

# Ubuntu/Linux 64-bit, CPU only:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl

# Mac OS X, CPU only:
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py2-none-any.whl

when I command pip install protobuf, I get the error:

Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

If you have the same problem as me, you should do the following commands.

pip install --ignore-installed six sudo pip install protobuf

According to your comments, you have multiply versions of python what could happend is that you install the package with pip of anthor python

pip is actually link to script that donwload and install your package.

two possible solutions:

  1. go to $(PYTHONPATH)/Scripts and run pip from that folder that way you insure you use the correct pip
  2. create alias to pip which points to $(PYTHONPATH)/Scripts/pip and then run pip install

how will you know it worked? Simple if the new pip is used the package will be install successfully, otherwise the package is already installed

I installed the protobuf with this command:

conda install -c anaconda protobuf=2.6.1

(you should check the version of protobuf)

In my case, MacOS has the permission control. sudo -H pip3 install protobuf

I had this problem to when I had a google.py file in my project files.
It is quite easy to reproduce.
main.py: import tensorflow as tf
google.py: print("Protobuf error due to google.py")

Not sure if this is a bug and where to report it.

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