Barry Rosenberg
Barry Rosenberg

Reputation: 2227

TensorFlow pip installation issue: cannot import name 'descriptor'

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'

Upvotes: 11

Views: 61423

Answers (4)

Prashanth R
Prashanth R

Reputation: 116

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!

Upvotes: 4

Jasper
Jasper

Reputation: 182

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

Upvotes: 1

bob marti
bob marti

Reputation: 1569

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

Upvotes: 0

Barry Rosenberg
Barry Rosenberg

Reputation: 2227

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.

Upvotes: 7

Related Questions