TensorFlow GPU版本號與CUDA的對應產生的錯誤


前言

 

感悟:cuda 8.0+cudnn 6.0+TensorFlow 1.3 
cuda 9.0+cudnn 7.0+TensorFlow 1.7
python3.6.2+cuda 9.0+cudnn7.5+Tensorflow 1.10.0+Anaconda4.6.11

最近在新的工作站上重新裝TensorFlow的GPU版本,剛開始由於省事,直接更新到最新版本1.13,然后輸入hello TensorFlow程序。但是卻報錯“ImportError: DLL load failed: 找不到指定的模塊”。無奈之下,各種百度,看到有個比較舊博客提議將TensorFlow版本降低到1.4,於是先卸載再重裝,一頓修改之后,又報錯“Could not find 'cudart64_80.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 8.0 from this URL: https://developer.nvidia.com/cuda-toolkit”,這句話的意思就是說我裝的TensorFlow版本太低,只能支持CUDA8.0,但是我裝的是CUDA9.0,所以出現了不對應。后來,又卸載當前TensorFlow環境,指定安裝1.7版本,搞定。特此記錄下來,防止后人少踩坑。

以下圖示均為命令行操作

TensorFlow版本過低,CUDA版本過高

 具體報錯如下:

(tensorflow-gpu) C:\Users\WW>python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\platform\self_check.py", line 75, in preload_check
    ctypes.WinDLL(build_info.cudart_dll_name)
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模塊。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
    self_check.preload_check()
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\platform\self_check.py", line 82, in preload_check
    % (build_info.cudart_dll_name, build_info.cuda_version_number))
ImportError: Could not find 'cudart64_80.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 8.0 from this URL: https://developer.nvidia.com/cuda-toolkit

 

TensorFlow版本過高,CUDA版本過低

 具體錯誤如下所示:

(tensorflow-gpu) C:\Users\WW>python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\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 "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模塊。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\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 "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "D:\TensorFlow\Anaconda\Anaconda\envs\tensorflow-gpu\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模塊。


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.

 

TensorFlow與CUDA版本的對應關系

附上幾張表格:

具體最新版本對應可參考TensorFlow中文網址:https://www.tensorflow.org/install/source#tested_source_configurations

總結

  1. 安裝環境時參考的博客一定要注意時間,時間,時間。有可能當時可以的現在就不一定行了,版本問題真的很煩人吶吶吶
  2. 切勿貪圖省事,更新到最新版本,要提前了解清楚,然后再裝對應的版本

參考

https://blog.csdn.net/yeler082/article/details/80943040

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM