简体   繁体   中英

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.

尝试手动删除库文件并使用pip重新安装

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

What I did was clicking

Runtime -> Restart Runtime

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM