错误:无法加载本地的 TensorFlow 运行时

34

今天我使用以下命令安装了TensorFlow:

C:\>pip3 install --upgrade tensorflow
Collecting tensorflow
  Using cached tensorflow-1.2.0-cp35-cp35m-win_amd64.whl
Requirement already up-to-date: bleach==1.5.0 in c:\python35\lib\site-packages (
from tensorflow)
Requirement already up-to-date: werkzeug>=0.11.10 in c:\python35\lib\site-packag
es (from tensorflow)
Requirement already up-to-date: html5lib==0.9999999 in c:\python35\lib\site-pack
ages (from tensorflow)
Requirement already up-to-date: protobuf>=3.2.0 in c:\python35\lib\site-packages
 (from tensorflow)
Requirement already up-to-date: backports.weakref==1.0rc1 in c:\python35\lib\sit
e-packages (from tensorflow)
Requirement already up-to-date: markdown==2.2.0 in c:\python35\lib\site-packages
 (from tensorflow)
Requirement already up-to-date: numpy>=1.11.0 in c:\python35\lib\site-packages (
from tensorflow)
Requirement already up-to-date: six>=1.10.0 in c:\python35\lib\site-packages (fr
om tensorflow)
Requirement already up-to-date: wheel>=0.26 in c:\python35\lib\site-packages (fr
om tensorflow)
Requirement already up-to-date: setuptools in c:\python35\lib\site-packages (fro
m protobuf>=3.2.0->tensorflow)
Installing collected packages: tensorflow
Successfully installed tensorflow-1.2.0

当我尝试导入TensorFlow时,它会抛出以下错误:

"When I tried to import TensorFlow, it throws:" --> "当我尝试导入TensorFlow时,它会抛出:"
C:\>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_intern
al.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Python35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", l
ine 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_intern
al.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_intern
al.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Python35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python35\lib\site-packages\tensorflow\__init__.py", line 24, in <modu
le>
    from tensorflow.python import *
  File "C:\Python35\lib\site-packages\tensorflow\python\__init__.py", line 49, i
n <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", l
ine 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_intern
al.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Python35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", l
ine 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_intern
al.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_intern
al.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Python35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_probl
ems

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

我正在使用Python 3.5.2 64位版本。我不太清楚为什么导入过程会出错。


请参见 https://www.tensorflow.org/install/install_sources#common_installation_problems。 - moritzg
2
可能是运行基本TensorFlow示例的错误的重复问题。 - moritzg
3
谢谢,问题已解决。解决方案是从Visual C++ 2015 Redist安装MSVCP140.dll。 - galih
https://dev59.com/QlgQ5IYBdhLWcg3w7oVA - user8407851
14个回答

15

在执行了这一行代码后,我的程序完美地运行了:

pip install tensorflow --upgrade --force-reinstall

12

先卸载这个

pip uninstall tensorflow

现在重新安装,请下载此tensorflow wheel文件

使用以下方式进行安装(在相同目录下)

pip install tensorflow-1.6.0-cp36-cp36m-win_amd64.whl

这个问题困扰了我一个星期了,这是唯一有效的方法。感谢分享。 - Sotos
3
如果你的CPU不支持AVX指令集,当使用tensorflow官方1.6.0及以上版本(通过pip install tensorflow安装)时,你会遇到以下错误:ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed. (Win 10) 或 ImportError: DLL load failed with error code -1073741795 (Win 7)。你可以使用从sse2文件夹下载的[filename].whl文件,而不是使用官方的AVX二进制文件来解决这个问题。这些文件可以在Tensor Flow Wheels for Windows上找到。 - Memochipan
"pip install tensorflow"是像我这样刚开始学习TensorFlow时尝试的第一个命令,不知道下载的版本可能与电脑性能不匹配。现在我知道我可以使用“wheels”下载特定版本。 - Memochipan
OP使用的是Python 3.5,下载并安装为Python 3.6编译的wheel包不会解决他们的问题。 - Martijn Pieters

4

谢谢。我在工作中必须使用Windows 10,这对我很有用。 - Hagbard
这对我的情况没有帮助。 - Danijel

4
只需下载MSVCP140.dll,解压缩并将其粘贴到system32文件夹中即可。

文件夹链接为 https://www.dll-files.com/msvcp140.dll.html - Kasparov92

3

您可以尝试降级TensorFlow或使用最新版本的TensorFlow。

pip install tensorflow

如果出现问题,请尝试以下代码:pip install --user tensorflow==2.0.0 - Biman Pal

3

如果你想使用具有最少依赖项的 Tensorflow 版本 2,请使用此版本:

pip install tensorflow==2.0.0b1

2

我在安装Python 3.6的TensorFlow时,在OSX Siera上遇到了类似的错误。通过使用二进制URL来识别TensorFlow Python软件包,这个问题得到了解决。

sudo pip3 install --upgrade tfBinaryURL   # Python 3.n

在我的情况下,tfBinaryURL 的链接如下:

sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.3.0-py3-none-any.whl

1
谢谢,这帮了我很多。我在OS X El Capitan上遇到了同样的问题,幸亏有你的解决方案解决了它。 - user2804064
谢谢,由于您的解决方案,我的问题已经得以解决。 - Luca Squadrone

2

1) 我执行了以下命令:pip uninstall tensorflow
2) 从tensorflow wheel下载了文件
3) 然后执行了以下命令:pip install tensorflow-1.6.0-cp36-cp36m-win_amd64.whl

但是我遇到了以下错误:

错误:tensorflow-1.6.0-cp36-cp36m-win_amd64.whl不支持此平台。

所以我尝试在已安装的Anaconda Navigator中将tensorflow作为依赖项安装
这样做对我起了作用!


2

今天我也遇到了同样的问题,我按照这里以及其他互联网来源和自己的思路给出的建议都尝试了,但都没有解决问题。

我已经安装了tf 1.2.0,并且导入没有任何问题。

pip3 install --upgrade tensorflow==1.2.0

进一步了解后,我发现所有版本都可以很好地导入,直到1.6.0版本,所以我将使用1.5.0版本。目前最新版本是1.7.0。


2

对于使用 macOS X 版本 < 10.12.6 的 Mac 用户,请安装 TensorFlow 版本 1.5:

pip install tensorflow==1.5


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接