11

After successfully pip install, importing the tensorflow library fails.

>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 4, in <module>
    from tensorflow.python import *
  File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 13, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/Library/Python/2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 8, in <module>
    from google.protobuf import reflection as _reflection
  File "/Library/Python/2.7/site-packages/google/protobuf/reflection.py", line 58, in <module>
    from google.protobuf.internal import python_message as message_impl
  File "/Library/Python/2.7/site-packages/google/protobuf/internal/python_message.py", line 59, in <module>
    import six.moves.copyreg as copyreg
ImportError: No module named copyreg
MattMcKnight
  • 8,185
  • 28
  • 35
feng
  • 143
  • 1
  • 1
  • 3

4 Answers4

21

You can upgrade to six-1.10.x using

easy_install -U six

This will upgrade the current version of six from 1.4 to 1.10.x, that is required by tensorflow.

Abhilash Panigrahi
  • 1,455
  • 1
  • 13
  • 31
3

Solution: TensorFlow depends on protobuf which require six-1.10.0. Apple's default python environment has six-1.4.1 and may be difficult to upgrade. So we recommend either installing a separate copy of python via homebrew:

brew install python

or building / using TensorFlow within virtualenv as described above.

Evan Cater
  • 31
  • 1
  • 2
  • 5
    Upgrading six might not be that difficult. Try running `easy_install -U six` Up-to-date instructions [here](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#on-macosx-) – dsmilkov Nov 10 '15 at 04:47
  • 1
    thanks a lot, brew install python solved my problem – feng Nov 11 '15 at 04:13
  • brew install python did it for me too – atlex2 Nov 12 '15 at 06:08
1

copyreg is a python3 function that is available in the six module in python2.x, see https://docs.python.org/2/library/copy_reg.html#module-copy_reg

To get copyreg, you have to install six:

pip install -U six

(Note: In python2, you access can either access the function with (i) six.copy_reg or when a module is imported with six.moves.*, it keeps the python3 syntax, i.e. six.moves.copyreg)

alvas
  • 115,346
  • 109
  • 446
  • 738
0

Since non of the suggested fixes worked for me, I changed the line

import six.moves.copyreg as copyreg

to

from six.moves import copyreg

and this seemed like this fixed this problem. However, I got another ImportError instead saying

dlopen(/Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so, 2): no suitable image found.  Did find:
/Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: mach-o, but wrong architecture

Just posting this as an answer if someone else maybe has more success in this than me.

woodenflute
  • 325
  • 2
  • 7