10
votes

I am working with an Ubuntu 14.04 machine, trying to import the google.protobuf module into python 2.7.

I have tried

apt-get python-protobuf 

and

pip install protobuf 

without success.

Inside python, I get an error saying:

"ImportError: No module named google.protobuf"

Edit 1:

Sorry and thank you to everyone who commented. I'm still new to Ubuntu and StackOverflow.

Specifically, I type in to command line

python
import google.protobuf

and get the feedback

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

ImportError: No module named google.protobuf

I then type

exit()

I tried inputting

sudo apt-get install python-protobuf

which responds with

Reading package lists... Done Building dependency tree
Reading state information... Done python-protobuf is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 283 not upgraded.

Then I go back into python and try

import google.protobuf

again, but I get exactly the same error as before.

Finally, I tried

pip install protobuf

which responded with

Requirement already satisfied: protobuf in /usr/local/lib/python2.7/dist-packages

Requirement already satisfied: six>=1.9 in /usr/local/lib/python2.7/dist-packages (from protobuf)

Requirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf)

I tried

python
import google.protobuf

and got exactly the same error. Putting

import protobuf

into python also gets the same error.

Some related information: I have tried doing multiple uninstalls/reinstalls with both apt-get and pip to fix th error, with no change. Also, one of the first things I did after getting Ubuntu was to download python 2.7 from the website and install it, not realizing python came with Ubuntu.

Thanks again.

1
i'm may not be correct, but try just import protobuf with the google. part. If that doesn't work, likely something is wrong with your pip. - eshanrh
you need to added details of your trouble, what do you mean without success. - Brown Bear
Please show your code or the trace in the terminal with the error. Since Stack Overflow hides the Close reason from you: Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. - jww
very late to the party, but try $ python -m pip install protobuf. To me this smells like classic using-pip-for-different-python-version/instalation problem. To find out which python version does the pip command correspond try $ which pip - Robin Nemeth

1 Answers

1
votes
pip install --ignore-installed six

sudo pip install protobuf