【问题标题】:Import Tensorflow without NVIDIA GPU (ImportError: Could not find 'nvcuda.dll')在没有 NVIDIA GPU 的情况下导入 Tensorflow(ImportError: 找不到 'nvcuda.dll')
【发布时间】:2020-04-29 13:11:31
【问题描述】:

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

   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?

【问题讨论】:

  • 你安装tensorflow的命令是什么?
  • 我使用了 Anaconda Navigator。这些包称为“tensorflow (2.1.0)”、“tensorflow-base”、“tensorflow-estimate”。它们是在安装“keras”后安装的
  • 你能卸载它并在终端运行这个命令conda install -c conda-forge tensorflow吗?
  • 太棒了!谢谢,它有效。您能否为这个问题写一个简短的答案并简要解释为什么这个解决方案有效?那太棒了。
  • 很高兴能帮上忙,我已按要求添加了答案!

标签: python tensorflow anaconda


【解决方案1】:

正如 cmets 中所讨论的,问题仅出在您的安装中。使用 anaconda-navigator 并不是安装tensorflow 的最佳方式。我的假设是 tensorflow-basetensorflow-estimate 具有 GPU 依赖性,这就是它不断显示发布的错误消息的原因。

使用conda 安装tensorflow 的最佳方式是通过conda-forge 通道,这是官方方式。你可以通过运行来做到这一点:

conda install -c conda-forge tensorflow

【讨论】:

    猜你喜欢
    • 2018-08-30
    • 1970-01-01
    • 2020-08-05
    • 2021-09-28
    • 2019-02-01
    • 2022-01-03
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    相关资源
    最近更新 更多