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
2

4 Answers 4

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.

2
  • @Mandy You are welcome! Commented Nov 11, 2015 at 7:10
  • 1
    Thank you. The upgrade worked for me. I also upgraded numpy too in the same way easy_install -U numpy because numpy version 1.9.2 or later was required. Commented Nov 13, 2015 at 4:13
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.

3
  • 5
    Upgrading six might not be that difficult. Try running easy_install -U six Up-to-date instructions here
    – dsmilkov
    Commented Nov 10, 2015 at 4:47
  • 1
    thanks a lot, brew install python solved my problem
    – feng
    Commented Nov 11, 2015 at 4:13
  • brew install python did it for me too
    – atlex2
    Commented Nov 12, 2015 at 6: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)

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.

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