最近,我已经完成了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我已经想了好几个小时了,有没有人遇到过这个或类似的错误?我看过安装手册,并遵循了我所能做的每一步。我试过重装原型机
我不会在tensorflow目录上运行我的测试文件。
我真的很感激任何帮助,因为这个错误正在耗尽我的大脑。
发布于 2018-11-27 22:49:23
尝试手动删除库文件并使用pip重新安装它。
发布于 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
发布于 2020-07-08 11:34:06
我所做的就是点击
运行时->重新启动运行时
再一次运行代码,就像魔法一样。
https://stackoverflow.com/questions/53509213
复制相似问题