首页 > 解决方案 > 在没有 NVIDIA GPU 的情况下导入 Tensorflow(ImportError: 找不到 'nvcuda.dll')

问题描述

我已经tensorflow使用 Anaconda Navigator 安装了该软件包。当我尝试import tensorflow在 jupyter notebook 中运行时,出现以下错误:

   OSError                                   Traceback (most recent call last)
D:\ProgrammFiles\Anaconda\lib\site-packages\tensorflow\python\platform\self_check.py in preload_check()
     61         try:
---> 62           ctypes.WinDLL(build_info.nvcuda_dll_name)
     63         except OSError:

D:\ProgrammFiles\Anaconda\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
    365         else:

OSError: [WinError 126] Det går inte att hitta den angivna modulen

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-8-d6579f534729> in <module>
----> 1 import tensorflow

D:\ProgrammFiles\Anaconda\lib\site-packages\tensorflow\__init__.py in <module>
     26 
     27 # pylint: disable=g-bad-import-order
---> 28 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     29 from tensorflow.python.tools import module_util as _module_util
     30 

D:\ProgrammFiles\Anaconda\lib\site-packages\tensorflow\python\__init__.py in <module>
     47 import numpy as np
     48 
---> 49 from tensorflow.python import pywrap_tensorflow
     50 
     51 # Protocol buffers

D:\ProgrammFiles\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     28 # Perform pre-load sanity checks in order to produce a more actionable error
     29 # than we get from an error during SWIG import.
---> 30 self_check.preload_check()
     31 
     32 # pylint: disable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

D:\ProgrammFiles\Anaconda\lib\site-packages\tensorflow\python\platform\self_check.py in preload_check()
     68               "'C:\\Windows\\System32'. If it is not present, ensure that you "
     69               "have a CUDA-capable GPU with the correct driver installed."
---> 70               % build_info.nvcuda_dll_name)
     71 
     72       if hasattr(build_info, "cudart_dll_name") and hasattr(

ImportError: Could not find 'nvcuda.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Typically it is installed in 'C:\Windows\System32'. If it is not present, ensure that you have a CUDA-capable GPU with the correct driver installed.

我知道我无法使用tensorflow-gpu,因为我没有 NVIDIA GPU。因此,我什至没有安装该tensorflow-gpu软件包。

我应该如何在没有安装 CUDA 的情况下导入 TensorFlow?

标签: pythontensorflowanaconda

解决方案


正如评论中所讨论的,问题仅出在您的安装中。使用 anaconda-navigator 不是安装tensorflow. 我的假设是tensorflow-base或者tensorflow-estimate具有 GPU 依赖关系,这就是它不断显示发布的错误消息的原因。

最好的安装方式是通过tensorflow官方渠道安装。你可以通过运行来做到这一点:condaconda-forge

conda install -c conda-forge tensorflow

推荐阅读