导入张量流为tf时导入Tensorflow时出错

问题描述 投票:1回答:2

我最近经历了tensorflow的安装(并且有点挣扎)当我相信我已经得到它时,我现在在运行仅包含import tensorflow as tf的文件时遇到这些导入错误,我运行cmd:python3 tftest.py并获取这些导入错误:

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.

我确实安装了tensorflow

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

我一直试图弄清楚这几个小时,有没有人遇到过这个或类似的错误?我查看了安装手册,并按照我的每一步进行操作。我试过reintalling protobuf

我没有在tensorflow目录上运行我的测试文件。

我真的非常感谢任何帮助,因为这个错误正在耗尽我的大脑。

python tensorflow import install
2个回答
1
投票

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


0
投票

检查pip list没有安装tensorflow-gpu库,因为不支持某些GPU。

如果是这种情况,请卸载tensor flow-gpu和tensorflow-estimator并重新安装tensorflow: pip uninstall tensorflow-gpu pip uninstall tensorflow-estimator pip install tensorflow 确保使用pip -V命令使用python 3.6

© www.soinside.com 2019 - 2024. All rights reserved.