【问题标题】:Cannot install Tensorflow on Ubuntu Linux无法在 Ubuntu Linux 上安装 TensorFlow
【发布时间】:2021-05-28 01:33:16
【问题描述】:

系统信息
MacBook Air M1
Ubuntu Linux 20.04 使用虚拟机
Python 3.8.5 64 位

我已经安装了张量流,但是在导入库并编译任何代码后,它给了我以下一组错误

Traceback (most recent call last):
  File "/home/mradulagrawal/Desktop/IP/image.py", line 2, in <module>
    import tensorflow
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/mradulagrawal/.local/lib/python3.8/site-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.8/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.8/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header


Failed to load the native TensorFlow runtime.

See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
mradulagrawal@ubuntu:~/Desktop$ /usr/bin/python3 /home/mradulagrawal/Desktop/IP/image.py
Traceback (most recent call last):
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/mradulagrawal/.local/lib/python3.8/site-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.8/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.8/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mradulagrawal/Desktop/IP/image.py", line 2, in <module>
    import tensorflow
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/mradulagrawal/.local/lib/python3.8/site-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.8/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.8/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/mradulagrawal/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header


Failed to load the native TensorFlow runtime.

See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

谢谢!

【问题讨论】:

  • 进展如何?只是检查一下提供的信息是否有帮助。

标签: python tensorflow visual-studio-code pip


【解决方案1】:

根据你提供的信息,问题出现在安装的模块“tensorflow”的相关文件中。

建议你在这个python环境中找到“tensorflow”模块的安装包文件夹,尝试删除,然后重新安装,避免部分文件损坏或不兼容。

我们可以使用“pip show module”来查找模块的安装位置:

【讨论】:

    猜你喜欢
    • 2015-08-19
    • 2016-02-25
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    相关资源
    最近更新 更多