可以在 Jupyter 笔记本中导入 TensorFlow,但在 IDLE 中却不行

可以在 Jupyter 笔记本中导入 TensorFlow,但在 IDLE 中却不行

我在 Windows 7 SP1 上为 Python 3.7.2 安装了 tensorflow2.0.0-alpha0。它在 Jupyter 笔记本中导入正常,但当我尝试在 IDLE 或从命令行调用的 Python 解释器中导入它时,我收到此错误消息。

>>> import tensorflow
Traceback (most recent call last):
  File "C:\Users\SHARMA\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\platform\self_check.py", line 47, in preload_check
    ctypes.WinDLL(build_info.msvcp_dll_name)
  File "C:\Users\SHARMA\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

在处理上述异常的过程中,又发生了另一个异常:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import tensorflow
  File "C:\Users\SHARMA\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 27, in <module>
    from tensorflow._api.v2 import audio
  File "C:\Users\SHARMA\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\_api\v2\audio\__init__.py", line 8, in <module>
    from tensorflow.python.ops.gen_audio_ops import decode_wav
  File "C:\Users\SHARMA\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\SHARMA\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
    self_check.preload_check()
  File "C:\Users\SHARMA\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\platform\self_check.py", line 55, in preload_check
    % build_info.msvcp_dll_name)
ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. You may install this DLL by downloading Visual C++ 2015 Redistributable Update 3 from this URL: https://www.microsoft.com/en-us/download/details.aspx?id=53587

我该如何修复此问题以便 TensorFlow 在 IDLE 中工作?

答案1

我从 python37 中的一个子文件夹中复制了 msvcp140.dll,并将其粘贴到主 python37 文件夹中(其中包含 python、pythonw 等文件)。现在我能够在 IDLE 中导入 Tensorflow,并从命令提示符调用 python 解释器。我提到的问题似乎已经解决。但我不知道这是否是正确的解决方案。但到目前为止还没有出现任何问题。

相关内容