tensorflow.python.pywrap_tensorflow_internal没有模块Windows 10 tensorflow gpu

时间:2019-03-16 18:29:22

标签: python windows tensorflow

“ tensorflow-cpu”在装有Windows 10的设备上正常运行。 我正在尝试安装tensorflow-gpu,安装后无法导入,显示以下错误。

  

tensorflow.python.pywrap_tensorflow_internal没有模块

我已经安装了以下内容

  

CUDA 10.1

     

Nvidia图形驱动程序419版

     

CUDnn for CUDA 10.1

     

VC ++ 2015 REDIST

谁能说我在这里想念的是完整的错误消息。

Traceback (most recent call last):
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\Program Files\Python\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\Program Files\Python\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
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 "<stdin>", line 1, in <module>
  File "D:\Program Files\Python\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\Program Files\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\Program Files\Python\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\Program Files\Python\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

1 个答案:

答案 0 :(得分:0)

如果确定Windows计算机上已安装 Visual C ++ 2015 Redist ,则可能是 CUDA 版本与 Tensorflow 之间的版本冲突。强>版本。由于较新的版本存在一些冲突,并且在张量流方面更多,因此需要准确的CUDA版本和CUDnn库才能使其正常工作。

正确配置它的最佳方法是使用 Anaconda 安装和配置tensorflow-gpu,因为conda会自动为相应的tensorflow下载所有必需的CUDA和CUDnn版本

问题是新的Anaconda默认使用Python 3.7.x,而tensorflow或tensorflow-gpu不支持

因此安装Anaconda可以下载here

现在,通过在Anaconda Prompt中键入以下内容,使用配置了python 3.6.x的conda创建虚拟环境

conda create -n yourenvname python=3.6 anaconda

现在输入

即可切换到您的环境
conda activate yourenvname

现在使用来检查python版本,它应该显示类似这样的内容

> python --version
Python 3.6.7 :: Anaconda custom (64-bit)

现在终于安装tensorflow-gpu

conda install tensorflow-gpu

现在打开python并尝试导入tensorflow

>>> import tensorflow as tf
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

enter image description here

恭喜!一切都准备好了。