无法在 tensorflow CPU 上加载动态库 'cudart64_101.dll' - 仅安装

Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

我刚刚通过 pip install tensorflow 安装了最新版本的 Tensorflow,每当我 运行 一个程序时,我都会收到日志消息:

W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found

这很糟糕吗?我该如何修复错误?

张量流 2.1+

怎么回事?

对于 new Tensorflow 2.1 release,默认的 tensorflow pip 包包含 CPU 和 GPU 版本的 TF。在以前的 TF 版本中,找不到 CUDA 库会发出错误并引发异常,而现在库会动态搜索正确的 CUDA 版本,如果找不到,则会发出警告(开头的 W 代表警告,错误有一个 E (或 F 代表致命错误)并返回到 CPU-only 模式。事实上,这也在警告后立即作为信息消息写入日志(请注意,如果您的最低日志级别高于默认值,您可能看不到信息消息)。完整日志是(强调我的):

2020-01-20 12:27:44.554767: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found

2020-01-20 12:27:44.554964: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

我应该担心吗?我该如何解决?

如果您的机器上没有支持 CUDA 的 GPU,或者如果您不关心没有 GPU 加速,则无需担心。另一方面,如果您安装了 tensorflow 并需要 GPU 加速,请检查您的 CUDA 安装(TF 2.1 需要 CUDA 10.1not 10.2 或 10.0 ).

如果您只是想消除警告,您可以adapt TF's logging level 抑制警告,但这可能有点矫枉过正,因为它会使所有 警告静音。


Tensorflow 1.X 或 2.0:

您的 CUDA 设置已损坏,请确保安装了正确的版本。

在 TensorFlow 2.1 中安装 GPU 支持的先决条件:

  1. 安装最新的 GPU 驱动程序。
  2. 安装CUDA 10.1
    • 如果 CUDA 安装程序报告 "you are installing an older driver version",您可能希望选择自定义安装并取消选择某些组件。事实上,请注意,TensorFlow 不需要与 CUDA 捆绑的软件,包括 GeForce Experience、PhysX、显示驱动程序和 Visual Studio 集成。
    • 另请注意,除非您从源代码构建,否则 TensorFlow 需要特定版本的 CUDA 工具包;对于 TensorFlow 2.1 和 2.2,当前版本为 10.1。
  3. 安装 cuDNN。
    1. Download cuDNN 适用于 CUDA 10.1 的 v7.6.4。这将要求您注册 NVIDIA 开发者计划。
    2. 解压缩到合适的位置并将 bin 目录添加到您的 PATH。
  4. 通过 pip install tensorflow 安装 tensorflow。
  5. .

我用另一种方式解决了这个问题。 首先,我从这个 link.

安装了 cuda 10.1 工具包

我选择了安装程序类型:exe(local)(对于 windows)并在自定义模式下安装了 10.1(没有 visual studio 集成,NVIDIA PhysX 因为之前我安装了 CUDA 10.2 所以需要依赖项已自动安装)

安装后,从以下路径 (C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin) ,就我而言,我复制了 cudart64_101.dll 文件并粘贴到 (C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin).

然后导入 Tensorflow 就顺利了。

这个 solution 对我有用:

我用anaconda预装了环境(这里是代码)

conda create -n YOURENVNAME python=3.6 // 3.6> incompatible with keras
conda activate YOURENVNAME
conda install tensorflow-gpu
conda install -c anaconda keras
conda install -c anaconda scikit-learn
conda install matplotlib

但在我收到这些警告之后

2020-02-23 13:31:44.910213: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found

2020-02-23 13:31:44.925815: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll

2020-02-23 13:31:44.941384: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll

2020-02-23 13:31:44.947427: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll

2020-02-23 13:31:44.965893: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll

2020-02-23 13:31:44.982990: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll

2020-02-23 13:31:44.990036: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found

我是如何解决第一个警告的: 我只是在这里下载了一个包含所有 cudnn 文件(dll 等)的 zip 文件:https://developer.nvidia.com/cudnn

我是如何解决第二个警告的: 我在由 conda 创建的虚拟环境中查看了最后一个丢失的文件 (cudart64_101.dll),我只是 copy/pasted 它位于与 .dll cudnn

相同的 lib 文件夹中

一种更简单的方法是创建一个名为 cudart64_101.dll 的 link 以指向 cudart64_102.dll。这不是很正统,但由于 TensorFlow 正在寻找 cudart64_101.dll 导出的符号并且 nvidia 人员不是业余爱好者,他们很可能不会从 101 到 102 中删除符号。它有效,基于这个假设(里程可能会有所不同) .

Tensorflow 2.1 适用于 Cuda 10.1。

如果您想快速破解:

  • 只需从 here 下载 cudart64_101.dll。解压缩 zip 文件并将 cudart64_101.dll 复制到您的 CUDA bin 目录

其他:

  • 安装 Cuda 10.1

conda 环境中,这就是解决我的问题的方法(我缺少 cudart64-100.dll:

  1. 下载自 dll-files.com/CUDART64_100.DLL

  2. 放在我的conda环境中 C:\Users\<user>\Anaconda3\envs\<env name>\Library\bin

就是这样!您可以仔细检查它是否正常工作:

import tensorflow as tf
tf.config.experimental.list_physical_devices('GPU')

Tensorflow gpu 2.2 和 2.3 每晚

(以及 CUDA 工具包 11.0 RC)

为了解决与 OP 相同的问题,我只需要在我的磁盘上找到 cudart64_101.dll(在我的例子中是 C:\Program Files\NVIDIA Corporation\NvStreamSrv) 并将其添加为变量环境(即添加值 C:\Program Files\NVIDIA\Corporation\NvStreamSrv)cudart64_101.dll 到用户的环境变量 Path).

能够通过将 NVIDIA 设备驱动程序更新到最新版本 (v446.14) 来解决问题。 NVIDIA 驱动程序下载 link here.

TensorFlow 2.3.0 在 CUDA 11 上运行良好。但是您必须安装 tf-nightly-gpu(在安装 tensorflow 和 CUDA 11 之后): https://pypi.org/project/tf-nightly-gpu/

尝试:

pip install tf-nightly-gpu

之后您将在控制台中收到消息:

I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_110.dll

如果您看到上述错误但实际上您安装了 CUDA 10,此答案可能会有所帮助:

pip install tensorflow-gpu==2.0.0

输出:

I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll

这是我的解决方案。

在我的例子中,tensorflow 安装正在寻找 cudart64_101.dll

cudart64_101的101部分是Cuda版本-这里101=10.1

我已经下载了11.x,所以我系统上的cudart64版本是cudart64_110.dll

这是错误的文件!! cudart64_101.dll≠cudart64_110.dll

解决方案

https://developer.nvidia.com/

下载 Cuda 10.1

安装(我的 NSight Visual Studio 集成崩溃,所以我关闭了它)

安装完成后你应该有一个 Cuda 10.1 文件夹,在 bin 中系统抱怨缺少 dll

检查10.1的bin文件夹路径是否注册为系统环境变量,所以加载库的时候会检查

如果系统没有立即选择路径,您可能需要重新启动

我安装了 cudatoolkit 11 并复制了 dll C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\binC:\Windows\System32。 它修复了 PyCharm 但不是 Anaconda jupyter:

[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { } incarnation: 6812190123916921346 , name: "/device:GPU:0" device_type: "GPU" memory_limit: 13429637120 locality { bus_id: 1
links { } } incarnation: 18025633343883307728 physical_device_desc: "device: 0, name: Quadro P5000, pci bus id: 0000:02:00.0, compute capability: 6.1" ]

下载 CUDA 工具包 11.0 RC

为了解决这个问题, 我刚在我的磁盘上找到 cudart64_101.dll ( C:\Program Files\NVIDIA Corporation\NvStreamSrv) 并将其添加为变量环境,即为用户添加值 (C:\Program Files\NVIDIA\Corporation\NvStreamSrv)cudart64_101.dll环境变量 Path).

我 运行 在混合使用 pip 和 conda 以安装 tensorflow 2.3 时遇到了这个问题。 (我用pip安装tensorflow 2.3b/c当时conda安装tensorflow 2.3坏了。)

我最终安装了错误版本的 cudatoolkit 和 cudnn。

为了解决这个问题,我只是 conda install 指定了特定版本的 cudatoolkit 和 cuda。

查看 https://www.tensorflow.org/install/source_windows?force_isolation=true#tested_build_configurations 以获取有关应协同工作的 tensorflow、cudatoolkit 和 cuda 版本的信息。

这可能是由于 python 的版本引起的,您也是 运行ning,我使用的是 Microsoft Store 中的 python 3.7,我 运行进入这个错误,切换到 python 3.10 修复它。