Debugging TensorFlow ImportError: DLL load failed Exception

I have encountered this error at least twice on two different machines and have spent too much time tracking down all different reasons it can occur.

import tensorflow
Traceback (most recent call last):
File "C:\...\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\...\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 666, in _load_unlocked
File "", line 577, in module_from_spec
File "", line 906, in create_module
File "", line 222, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

So anyone facing this issue (especially with TensorFlow 1.4.0) here is how to debug this:

  1. First make sure you have correct versions of CUDA Toolkit and cuDNN. NVidia has newer versions as default downloads and they won't work. See my post on TensorFlow installation.
  2. I would highly recommend using Python 3.5 version instead of 3.6 with TensorFlow 1.4. If you have latest Anaconda version, you probably have Python 3.6. You can check this by using command conda info. If you indeed have Python 3.6 then you can downgrade to 3.5 by using command conda install python=3.5.
  3. Make sure you have NVidia's CUDA Toolkit path as well as cuDNN path - both - listed before Anaconda path in Environment variable Path. Anaconda now seem to supply same DLLs in its own folder but they seem to cause ImportError.
  4. Use where command to actually see if you can find these DLLs on path:
                 where cuDNN64_6.dll
                 where curand64_80.dll
    

    The first path should be where you downloaded cuDNN 6 and the second path should be in NVidia's CUDA Toolkit folder.

  5. If you still get this error, download Process Monitor from sysinternals.  You will see icons to monitor registry, disk etc in toolbar. Disable those except for icon that says "Show Process and Thread Activities". Then click on filter icon and add a filter for ImagePath contains python. Now you should see only process and thread activities from python.exe. Close all python instances, open a new one and execute
    import tensorflow as tf

    . Now Process Monitor will show you DLLs being loaded by TensorFlow. The last DLL in this list is usually is the one causing problem.

Leave a Reply