首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导入Tensorflow时输入tensorflow时出错

导入Tensorflow时输入tensorflow时出错
EN

Stack Overflow用户
提问于 2018-11-27 22:28:38
回答 3查看 6.2K关注 0票数 2

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

代码语言:javascript
复制
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

代码语言:javascript
复制
Name: tensorflow
Version: 0.12.0
Location: /usr/local/lib/python3.4/dist-packages
Requires: numpy, six, protobuf, wheel

我已经想了好几个小时了,有没有人遇到过这个或类似的错误?我看过安装手册,并遵循了我所能做的每一步。我试过重装原型机

我不会在tensorflow目录上运行我的测试文件。

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-11-27 22:49:23

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

票数 1
EN

Stack Overflow用户

发布于 2019-03-19 16:40:14

通过pip list检查是否安装了tensorflow-gpu库,因为不支持某些GPU。

如果是这样的话,卸载张量流-gpu重新安装tensorflow

pip uninstall tensorflow-gpu

pip uninstall tensorflow-estimator

pip install tensorflow

确保在pip -V命令中使用python3.6

票数 0
EN

Stack Overflow用户

发布于 2020-07-08 11:34:06

我所做的就是点击

运行时->重新启动运行时

再一次运行代码,就像魔法一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53509213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档