11

I'm seeing the following error when installing TensorFlow:

ImportError: Traceback (most recent call last):
File ".../graph_pb2.py", line 6, in 
from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor'

4 Answers 4

7

This error signals a mismatch between protobuf and TensorFlow versions.

Take the following steps to fix this error:

  1. Uninstall TensorFlow.
  2. Uninstall protobuf (if protobuf is installed).
  3. Reinstall TensorFlow, which will also install the correct protobuf dependency.
4

I faced the similar issue, after trial and error, I used the below logic to run the program:

pip install --upgrade --no-deps --force-reinstall tensorflow

This will make sure to uninstall and reinstall the program from fresh. It works!

1

I would be extra careful before uninstalling/reinstalling other packages such as protobuf. What I think would most likely be the issue is difference in versions. As of writing this, the most recent release of python is 3.7 while tensorflow is only compatible up to 3.6.

If you're using a 3rd party distribution like Anaconda, this can get hidden from you. In this case I would recommend creating a new environment in Anaconda, with python 3.6 and then installing tensorflow: https://conda.io/projects/conda/en/latest/user-guide/getting-started.html#managing-python

0

Try this:

  1. pip uninstall protobuf

  2. brew install protobuf

  3. mkdir -p /Users/alexeibendebury/Library/Python/2.7/lib/python/site-packages

  4. echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/alexeibendebury/Library/Python/2.7/lib/python/site-packages/homebrew.pth

Not the answer you're looking for? Browse other questions tagged or ask your own question.