首页 > 解决方案 > 在 Windows 中导入 tensorflow 模块时遇到问题

问题描述

导入 tensorflow Traceback(最近一次调用最后):文件“D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 18 行,在 swig_import_helper fp,路径名,描述 = imp.find_module('_pywrap_tensorflow_internal' , [dirname( file )]) File "D:\python36\lib\imp.py", line 296, in find_module raise ImportError(_ERR_MSG.format(name), name=name) ImportError: No module named '_pywrap_tensorflow_internal'

在处理上述异常的过程中,又出现了一个异常:

Traceback(最近一次调用最后):文件“D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”,第 58 行,从 tensorflow.python.pywrap_tensorflow_internal 导入 * 文件“D:\python36\lib \site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 28 行,在 _pywrap_tensorflow_internal = swig_import_helper() 文件“D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 20 行,在 swig_import_helper导入_pywrap_tensorflow_internal ModuleNotFoundError:没有名为“_pywrap_tensorflow_internal”的模块

在处理上述异常的过程中,又出现了一个异常:

回溯(最近一次调用最后):文件“”,第 1 行,在文件“D:\python36\lib\site-packages\tensorflow__init__.py”中,第 24 行,在 from tensorflow.python import pywrap_tensorflow # pylint: disable=unused -import 文件“D:\python36\lib\site-packages\tensorflow\python__init__.py”,第 49 行,从 tensorflow.python 导入 pywrap_tensorflow 文件“D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow .py",第 74 行,在 raise ImportError(msg) ImportError: Traceback (last recent call last): File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",第 18 行,在 swig_import_helper fp,路径名,描述 = imp.find_module('_pywrap_tensorflow_internal', [dirname(文件)]) 文件“D:\python36\lib\imp.py”,第 296 行,在 find_module 中引发 ImportError(_ERR_MSG.format(name), name=name) ImportError: No module named '_pywrap_tensorflow_internal'

在处理上述异常的过程中,又出现了一个异常:

Traceback(最近一次调用最后):文件“D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”,第 58 行,从 tensorflow.python.pywrap_tensorflow_internal 导入 * 文件“D:\python36\lib \site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 28 行,在 _pywrap_tensorflow_internal = swig_import_helper() 文件“D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 20 行,在 swig_import_helper导入_pywrap_tensorflow_internal ModuleNotFoundError:没有名为“_pywrap_tensorflow_internal”的模块

无法加载原生 TensorFlow 运行时。

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

出于一些常见的原因和解决方案。寻求帮助时,请在此错误消息上方包含整个堆栈跟踪。

标签: python-3.xtensorflow

解决方案


1. 使用蟒蛇

Anaconda使用类似于 PyPI 的 conda 分布索引。TensorFlow conda 构建使用MKL(英特尔数学内核库)。它可以在没有 AVX 的情况下工作。

下载此处提到的 Anaconda并创建此处提到的新 conda 环境。

运行此命令:

conda install tensorflow

2. 使用来自tensorflow-windows-wheel 仓库的构建。

这个 repo 包含许多使用 SSE 而不是 AVX 构建的 TensorFlow pip wheel 文件。SSE 构建运行时没有任何编译错误。使用来自 repo 的这个文件。

希望这可以帮助。


推荐阅读