我最近已经完成了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
我已经尝试解决了几个小时,有人遇到过这个问题或类似的错误吗?我查看了安装手册,并按照我可能的每一个步骤进行操作。我尝试重新包装protobuf
我不在tensorflow目录上运行测试文件。
真的很感谢您的帮助,因为此错误使我的大脑筋疲力尽。
答案 0 :(得分:1)
尝试手动删除库文件,然后使用pip重新安装
答案 1 :(得分: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
答案 2 :(得分:0)
我所做的就是点击
运行时->重新启动运行时
然后重新运行代码,就像魔术一样。