首页 > 解决方案 > ImportError: Python 3.8 没有名为“_pywrap_tensorflow_internal”的模块

问题描述

我在 Windows 8 上安装了 Python 3.8 和 TensorFlow 1.12,但是,在编写此代码时(注意我没有使用 Anaconda):

import tensorflow as tf

我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\Dany\AppData\Local\Programs\Python\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "C:\Users\Dany\AppData\Local\Programs\Python\Python38-32\lib\imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Dany\AppData\Local\Programs\Python\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Dany\AppData\Local\Programs\Python\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Dany\AppData\Local\Programs\Python\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
  File "C:\Users\Dany\Desktop\FYP\Python files\NN.py", line 1, in <module>
    import tensorflow as tf

标签: pythonwindowstensorflowvisual-studio-codetensorflow2.0

解决方案


我在 Windows 8 上安装了 Python 3.8 和 TensorFlow 1.12

这种组合不起作用。当 tensorflow(即 TF)为 1.12 版本时,不支持 Python 3.8。它仅支持时TF (2.2.0rc1,2.2.0rc2)。请检查 pypi,对于1.12的 cp38 没有可用的文件。

如果您正在寻找兼容的 TF 1.12 的 python 版本是 3.5 到 3.7。如果您在安装时遇到任何问题,可能是编译器的原因,请安装MSVC 2015 update 3

在此处输入图像描述

请参阅 TF 测试的CPUGPU构建配置详细信息。

如果您对 TF 版本没有任何顾虑,我建议您安装适用于 Windows 8 64 位系统的 TF 2。请参阅此处的更多详细信息。

注意:安装 TF 2 后,如果您遇到任何 DLL 问题。可能的情况是

  1. 您需要安装 MSVC 2019
  2. 你的 CPU/Python 是 32 位的
  3. 您的 CPU 不支持 AVX2 指令
  4. 有一个库位于不同的位置/未安装在您的系统上,无法加载。

推荐阅读