Python (Tensorflow-GPU) 导入 tensorflow ImportError: 找不到 'cudnn64_7.dll'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48698536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:48:48  来源:igfitidea点击:

(Tensorflow-GPU) import tensorflow ImportError: Could not find 'cudnn64_7.dll'

pythontensorflow

提问by JShen

After created tensorflow environment under anaconda, I installed tensorflow-gpu. Then I was trying to import tensorflow to verify if it's correctly installed, but got this error:

在 anaconda 下创建 tensorflow 环境后,我安装了 tensorflow-gpu。然后我试图导入 tensorflow 以验证它是否正确安装,但出现此错误:

ImportError: Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 7 from this URL: https://developer.nvidia.com/cudnn

Setup is:

设置是:

NVIDIA GTX 1080
CUDA 9.0
cuDNN 6.0
tensorflow-gpu 1.5

Environment Variables are:

环境变量是:

CUDA_PAT: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
CUDA_PATH_V9_0: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

The %Path% variables are:

%Path% 变量是:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\libnvvp
C:\Users\yshen\AppData\Local\cudnn-8.0-windows10-x64-v6.0\cuda\bin

it is obvious that I installed cuDNN6.0, don't why the error shows "Could not find 'cudnn64_7.dll' ". Why it automatically searches cudnn64_7.dll instead of cudnn64_6.dll?

很明显我安装了cuDNN6.0,不知道为什么错误显示“找不到'cudnn64_7.dll'”。为什么它会自动搜索 cudnn64_7.dll 而不是 cudnn64_6.dll?

回答by mpeli

Also, I got below error when I installed TensorFlow 1.8. I have the Anaconda environment.

另外,当我安装TensorFlow 1.8. 我有 Anaconda 环境。

"ImportError: Could not find 'cudnn64_7.dll'"

“导入错误:找不到‘cudnn64_7.dll’”

But after I installed Nvidia cuDNN v7.1.3(April 17, 2018), for CUDA 9.0, everything started to work. Please note that one needs to sign up as a Nvidia developer to be able to download the installation package(s).

但是在我安装后Nvidia cuDNN v7.1.3(2018 年 4 月 17 日),对于CUDA 9.0,一切都开始工作了。请注意,需要注册为 Nvidia 开发人员才能下载安装包。

Then, just follow the instructions in the page : cudnn-install

然后,只需按照页面中的说明进行操作:cudnn-install

For Windows:

对于 Windows:

3.3. Installing cuDNN on Windows

3.3. 在 Windows 上安装 cuDNN

The following steps describe how to build a cuDNN dependent program. In the following sections:

以下步骤描述了如何构建 cuDNN 依赖程序。在以下部分:

-your CUDA directory path is referred to as C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

-您的 CUDA 目录路径称为 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

-your cuDNN directory path is referred to as <installpath>

-您的 cuDNN 目录路径称为 <installpath>

  1. Navigate to your <installpath>directory containing cuDNN.

  2. Unzip the cuDNN package. -cudnn-9.0-windows7-x64-v7.zipor -cudnn-9.0-windows10-x64-v7.zip

  3. Copy the following files into the CUDA Toolkit directory.

    • Copy <installpath>\cuda\bin\cudnn64_7.dllto C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin.
    • Copy <installpath>\cuda\ include\cudnn.hto C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include.
    • Copy <installpath>\cuda\lib\x64\cudnn.libto C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64.
  4. Set the following environment variables to point to where cuDNN is located. To access the value of the $(CUDA_PATH)environment variable, perform the following steps:

    • Open a command prompt from the Start menu.
    • Type Run and hit Enter.
    • Issue the control sysdm.cplcommand.
    • Select the Advanced tab at the top of the window.
    • Click Environment Variables at the bottom of the window.
    • Ensure the following values are set: Variable Name: CUDA_PATHVariable Value: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
  5. Include cudnn.lib in your Visual Studio project.

    • Open the Visual Studio project and right-clickon the project name.
    • Click Linker > Input > Additional Dependencies.
    • Add cudnn.liband click OK.
  1. 导航到<installpath>包含cuDNN.

  2. 解压缩 cuDNN 包。-cudnn-9.0-windows7-x64-v7.zip或者-cudnn-9.0-windows10-x64-v7.zip

  3. 将以下文件复制到 CUDA Toolkit 目录中。

    • 复制<installpath>\cuda\bin\cudnn64_7.dllC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin.
    • 复制<installpath>\cuda\ include\cudnn.hC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include.
    • 复制<installpath>\cuda\lib\x64\cudnn.libC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64.
  4. 设置以下环境变量以指向 cuDNN 所在的位置。要访问$(CUDA_PATH)环境变量的值,请执行以下步骤:

    • 从“开始”菜单打开命令提示符。
    • 输入 Run 并点击Enter
    • 发出控制sysdm.cpl命令。
    • 选择窗口顶部的高级选项卡。
    • 单击窗口底部的环境变量。
    • 确保设置了以下值: 变量名称: CUDA_PATH变量值:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
  5. 在 Visual Studio 项目中包含 cudnn.lib。

    • 打开 Visual Studio 项目并right-clickproject name.
    • 单击Linker > Input > Additional Dependencies
    • 添加cudnn.lib并单击OK

回答by user1586947

According to you previous answer, you seem to find out prebuilt tensorflow-gpu 1.5 is not compatible with CUDA 9.0 + CudNN 6.0. There are two possible solutions for your answer, if you want to use tensorflow-gpu 1.5:

根据您之前的回答,您似乎发现预构建的 tensorflow-gpu 1.5 与 CUDA 9.0 + CudNN 6.0 不兼容。如果您想使用 tensorflow-gpu 1.5,您的答案有两种可能的解决方案:

1, upgrade your CUDA tool chain to CUDA 9.0 +Cudnn 7.0 (currently Cudnn 7.0.5 for CUDA 9.0).

1、将你的CUDA工具链升级到CUDA 9.0+Cudnn 7.0(目前CUDA 9.0为Cudnn 7.0.5)。

2, recompile the tensorflow-gpu 1.5 target for CUDA 9.0 + cudnn 6.0.

2、为CUDA 9.0 + cudnn 6.0重新编译tensorflow-gpu 1.5 target。

I suggest choosing the first option for ease. But the official webpage of tensorflow 1.5 dose not deny the possibility of option 2: https://github.com/tensorflow/tensorflow/releases/tag/v1.5.0

我建议选择第一个选项以方便。但是tensorflow 1.5的官网并不否认选项2的可能性:https: //github.com/tensorflow/tensorflow/releases/tag/v1.5.0

回答by JShen

Just fould the solution:

只需提出解决方案:

I checked the \tensorflow\python\platform\build_info.py and found:

我检查了 \tensorflow\python\platform\build_info.py 并发现:

msvcp_dll_name = 'msvcp140.dll'
cudart_dll_name = 'cudart64_90.dll'
cuda_version_number = '9.0'
nvcuda_dll_name = 'nvcuda.dll'
cudnn_dll_name = 'cudnn64_7.dll'
cudnn_version_number = '7'

It assumes cudnn version is 7. So just need to correct it as:

它假设 cudnn 版本是 7。所以只需要将其更正为:

cudnn_dll_name = 'cudnn64_6.dll'
cudnn_version_number = '6'