导入具有GPU支持的TensorFlow时DLL加载失败

时间:2019-04-18 15:30:25

标签: windows tensorflow installation

我正在尝试在Windows 10上安装具有GPU支持的TensorFlow,但是导入它时出现错误(如下所示)。 CPU版本工作正常。

我有

  • 通过点子安装了tensorflow-gpu
  • 通过GeForce Experience更新了我的GTX 1050的NVidia驱动程序
  • 使用NVidia的网络安装程序安装了CUDA 10.1
  • installed cuDNN 7.5.0.56,负责复制正确CUDA文件夹中的每个文件
  • installed TensorRT 5.1.2.2通过zip方法并再次在CUDA中复制了相关的DLLs

这是错误:

> python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\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 "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, 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 "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\user\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\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\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 "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.


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.

我的PATH环境变量(我删除了所有非Microsoft和非NVidia条目):

> echo $env:PATH.Split(';')
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp
C:\Program Files\Microsoft MPI\Bin\
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\dotnet\
C:\Program Files (x86)\dotnet\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.1\
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\lib64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include
C:\Program Files\TensorRT-5.1.2.2\lib
C:\Program Files\TensorRT-5.1.2.2\bin
C:\tools\cuda\bin

TensorRT已安装在C:\Program Files\TensorRT-5.1.2.2中。

CUDA bin文件夹的内容:

PS C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin> ls


    Directory: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       18/04/2019     12:39                crt
-a----       09/02/2019     06:57         202752 bin2c.exe
-a----       09/02/2019     06:57       74850816 cublas64_10.dll
-a----       09/02/2019     06:57       36055552 cublasLt64_10.dll
-a----       09/02/2019     06:57         374272 cuda-memcheck.exe
-a----       09/02/2019     06:57        4320256 cudafe++.exe
-a----       09/02/2019     06:57         339968 cudart32_101.dll
-a----       09/02/2019     06:57         408064 cudart64_101.dll
-a----       18/04/2019     15:19      392566784 cudnn64_7.dll
-a----       09/02/2019     06:57      115644416 cufft64_10.dll
-a----       09/02/2019     06:57         225792 cufftw64_10.dll
-a----       09/02/2019     06:57        4785664 cuinj64_101.dll
-a----       09/02/2019     06:57        2074624 cuobjdump.exe
-a----       09/02/2019     06:57       49030656 curand64_10.dll
-a----       09/02/2019     06:57      171052032 cusolver64_10.dll
-a----       09/02/2019     06:57       87930368 cusparse64_10.dll
-a----       09/02/2019     06:57         285184 fatbinary.exe
-a----       09/02/2019     06:57        1323008 gpu-library-advisor.exe
-a----       09/02/2019     06:57         233472 nppc64_10.dll
-a----       09/02/2019     06:57       10049024 nppial64_10.dll
-a----       09/02/2019     06:57        3719680 nppicc64_10.dll
-a----       09/02/2019     06:57        1003008 nppicom64_10.dll
-a----       09/02/2019     06:57        7227904 nppidei64_10.dll
-a----       09/02/2019     06:57       46016512 nppif64_10.dll
-a----       09/02/2019     06:57       24603136 nppig64_10.dll
-a----       09/02/2019     06:57        5848064 nppim64_10.dll
-a----       09/02/2019     06:57       17426944 nppist64_10.dll
-a----       09/02/2019     06:57         194560 nppisu64_10.dll
-a----       09/02/2019     06:57        2610688 nppitc64_10.dll
-a----       09/02/2019     06:57        8202240 npps64_10.dll
-a----       09/02/2019     06:57         247296 nvblas64_10.dll
-a----       09/02/2019     06:57         384000 nvcc.exe
-a----       09/02/2019     06:57            310 nvcc.profile
-a----       09/02/2019     06:57       22919168 nvdisasm.exe
-a----       09/02/2019     06:57      149298688 nvgraph64_10.dll
-a----       18/04/2019     16:46      131539456 nvinfer.dll
-a----       18/04/2019     16:46        3663360 nvinfer_plugin.dll
-a----       09/02/2019     06:57        5960192 nvlink.exe
-a----       18/04/2019     16:46        4457472 nvonnxparser.dll
-a----       18/04/2019     16:46        2447872 nvparsers.dll
-a----       09/02/2019     06:57        4243456 nvprof.exe
-a----       09/02/2019     06:57         221696 nvprune.exe
-a----       09/02/2019     06:57        4580352 nvrtc-builtins64_101.dll
-a----       09/02/2019     06:57       15659520 nvrtc64_101_0.dll
-a----       09/02/2019     06:57             53 nvvp.bat
-a----       09/02/2019     06:57        5838336 ptxas.exe

C:\tools的内容:

PS C:\tools> tree /F
Folder PATH listing
Volume serial number is 6A54-3EA7
C:.
└───cuda
    │   NVIDIA_SLA_cuDNN_Support.txt
    │
    ├───bin
    │       cudnn64_7.dll
    │
    ├───include
    │       cudnn.h
    │
    └───lib
        └───x64
                cudnn.lib

3 个答案:

答案 0 :(得分:1)

问题是我安装了CUDA 10.1而不是10.0。 TensorFlow尚未与10.1兼容。

答案 1 :(得分:1)

是的,某些版本的TensorFlow不支持CUDA 10.1,在这种情况下,CUDA 10.0或更低版本将解决您的问题。

答案 2 :(得分:0)

这就是我的解决方法,如果您使用的是pip或pip3,则第一次成功的机会就较小。

  • 卸载Python,CUDA,CuNN,Tensorflow-gpu(如果已安装)
  • 安装ANACONDA或MINICONDA
  • 打开ANACONDA提示符并运行以下命令:

conda create --name tf_gpu tensorflow-gpu

  • 这将创建一个环境tf_gpu,其中将安装所有兼容版本的Python,CUDA,CuNN和Tensorflow
  • 安装完所有软件包后,打开ANACONDA提示符并键入以下命令

conda激活tf_gpu

  • 这会将conda'(base)'更改为'(tf_gpu)'环境
  • 然后像往常一样键入python来激活python提示符
  • 如果要停用'tf_gpu'环境

停用conda