ricknaght
ricknaght

Reputation: 93

Error importing Tensorflow when import tensorflow as tf

I've recently gone through the installation of tensorflow (and struggled a little) and when I believed I had got it, I now get these import errors when running a file that ONLY contains import tensorflow as tf, I ran the cmd: python3 tftest.py and get these import errors:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/usr/lib/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: /usr/local/lib/python3.4/dist-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "stockprice.py", line 1, in <module>
    import tensorflow as tf
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 60, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/usr/lib/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: /usr/local/lib/python3.4/dist-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header


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.

I do have tensorflow installed

Name: tensorflow
Version: 0.12.0
Location: /usr/local/lib/python3.4/dist-packages
Requires: numpy, six, protobuf, wheel

I've been trying to figure this out for hours, has anyone encountered this or a similar error? I've looked at installation manuals, and followed every single step I could. I've tried reintalling protobuf

I am not running my test file on the tensorflow directory.

I would really REALLY appreciate any help since this error is draining my brain out.

Upvotes: 2

Views: 15126

Answers (3)

Jo&#227;o Raffs
Jo&#227;o Raffs

Reputation: 195

What I did was clicking

Runtime -> Restart Runtime

and running the code all over again, it worked like magic.

Upvotes: 0

Mike D3ViD Tyson
Mike D3ViD Tyson

Reputation: 1771

check through pip list not to have installed the tensorflow-gpu library because some GPUs are not supported.

If this is the case, uninstall tensor flow-gpu and tensorflow-estimator and re-install tensorflow :

pip uninstall tensorflow-gpu

pip uninstall tensorflow-estimator

pip install tensorflow

make sure you use python 3.6 with the pip -V command

Upvotes: 0

SalvadorViramontes
SalvadorViramontes

Reputation: 580

Try to delete the library file manually and reinstall it using pip

Upvotes: 1

Related Questions