Search code examples
gitinstallationtensorflowimporterrorpython-wheel

Tensorflow Install from Source ImportError


I am trying to install tensorflow directly from the source using

git clone https://github.com/tensorflow/tensorflow and following the provided tutorial to build a wheel. Here is a full list of my commands used (bazel already installed) :

git clone https://github.com/tensorflow/tensorflow

sudo pip3 install dev
sudo pip3 install numpy
sudo pip3 install wheel

./configure (at tensorflow source directory)

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

sudo pip3 install /tmp/tensorflow_pkg/tensorflow-0.12.0rc0-cp35-none-any.whl

Up until this point everything works without error and the wheel file appears to be successfully installed as a module. However, when I try to import tensorflow in a python3 session, I received this error:

Traceback (most recent call last):

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Symbol not found: _PyCObject_Type

Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so

Expected in: flat namespace

in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

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

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 60, in <module>
raise ImportError(msg)

ImportError: Traceback (most recent call last):

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Symbol not found: _PyCObject_Type

Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so

Expected in: flat namespace

in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so


Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

Any suggestions appreciated, thanks!


Solution

  • The missing symbol _PyCObject_Type suggests that TensorFlow's C++ Python extension was compiled against a different version of Python from the one that built the PIP package. When you run ./configure before the bazel build, make sure that you answer the following prompt:

    Please specify the location of python. [Default is /usr/bin/python]: 
    

    ...with the correct path to your python 3.5 executable.