9

Trying to install the gpu version of Tensorflow on my machine, but I'm getting this error when trying 'import tensorflow'


ImportError Traceback (most recent call last) C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflo w_internal.py in swig_import_helper() 17 try: ---> 18 return importlib.import_module(mname) 19 except ImportError:

C:\Users\snh5_000\Anaconda3\lib\importlib__init__.py in import_module(name, pac kage) 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level) 127

C:\Users\snh5_000\Anaconda3\lib\importlib_bootstrap.py in _gcd_import(name, pac kage, level)

C:\Users\snh5_000\Anaconda3\lib\importlib_bootstrap.py in _find_and_load(name, import_)

C:\Users\snh5_000\Anaconda3\lib\importlib_bootstrap.py in _find_and_load_unlock ed(name, import_)

C:\Users\snh5_000\Anaconda3\lib\importlib_bootstrap.py in _load_unlocked(spec)

C:\Users\snh5_000\Anaconda3\lib\importlib_bootstrap.py in module_from_spec(spec )

C:\Users\snh5_000\Anaconda3\lib\importlib_bootstrap_external.py in create_modul e(self, spec)

C:\Users\snh5_000\Anaconda3\lib\importlib_bootstrap.py in _call_with_frames_rem oved(f, *args, **kwds)

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last) C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflo w.py in () 40 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL) ---> 41 from tensorflow.python.pywrap_tensorflow_internal import * 42 from tensorflow.python.pywrap_tensorflow_internal import version

C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflo w_internal.py in () 20 return importlib.import_module('_pywrap_tensorflow_internal' ) ---> 21 _pywrap_tensorflow_internal = swig_import_helper() 22 del swig_import_helper

C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflo w_internal.py in swig_import_helper() 19 except ImportError: ---> 20 return importlib.import_module('_pywrap_tensorflow_internal' ) 21 _pywrap_tensorflow_internal = swig_import_helper()

C:\Users\snh5_000\Anaconda3\lib\importlib__init__.py in import_module(name, pac kage) 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level) 127

ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last) in () ----> 1 import tensorflow

C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow__init__.py in () 22 23 # pylint: disable=wildcard-import ---> 24 from tensorflow.python import * 25 # pylint: enable=wildcard-import 26

C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python__init__.py in < module>() 49 import numpy as np 50 ---> 51 from tensorflow.python import pywrap_tensorflow 52 53 # Protocol buffers

C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflo w.py in () 50 for some common reasons and solutions. Include the entire stack trace 51 above this error message when asking for help.""" % traceback.format_exc () ---> 52 raise ImportError(msg) 53 54 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line- too-long

ImportError: Traceback (most recent call last): File "C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_t ensorflow_internal.py", line 18, in swig_import_helper return importlib.import_module(mname) File "C:\Users\snh5_000\Anaconda3\lib\importlib__init__.py", line 126, in imp ort_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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_t ensorflow.py", line 41, in from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_t ensorflow_internal.py", line 21, in _pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\snh5_000\Anaconda3\lib\site-packages\tensorflow\python\pywrap_t ensorflow_internal.py", line 20, in swig_import_helper return importlib.import_module('_pywrap_tensorflow_internal') File "C:\Users\snh5_000\Anaconda3\lib\importlib__init__.py", line 126, in imp ort_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named '_pywrap_tensorflow_internal'

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_probl ems

for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

Running Windows 10, Python 3.5.2, Anaconda 4.2.0 64-bit. Installed tensorflow-gpu using 'pip install tensorflow-gpu'.

I've attempted the fixes in https://github.com/tensorflow/tensorflow/issues/5949, namely running Microsoft Visual C++ 2015 Redistributable Update 3 and confirming I had the following DLLs in System32/SysWOW64/my Python folder:

KERNEL32.dll

WSOCK32.dll

WS2_32.dll

SHLWAPI.dll

python35.dll

MSVCP140.dll

VCRUNTIME140.dll

api-ms-win-crt-runtime-l1-1-0.dll

api-ms-win-crt-heap-l1-1-0.dll

api-ms-win-crt-utility-l1-1-0.dll

api-ms-win-crt-stdio-l1-1-0.dll

api-ms-win-crt-string-l1-1-0.dll

api-ms-win-crt-math-l1-1-0.dll

api-ms-win-crt-convert-l1-1-0.dll

api-ms-win-crt-environment-l1-1-0.dll

api-ms-win-crt-filesystem-l1-1-0.dll

api-ms-win-crt-time-l1-1-0.dll

It's worth noting that the cpu version of Tensorflow imports and runs just fine, but when I attempt to use the gpu version I get the above error. I presume this is due to a mistake on my part in configuring the CUDA toolkit/cudNN, but I think I did everything listed in the instructions correctly. I made sure I had an entry in the PATH environment variable for the CUDA toolkit (leading to \bin and \libnvvp) and added one in for cudNN (leading to \cuda).

Any thoughts or other information you'd need to help?

9 Answers 9

26

Try to rename cudnn64_6.dll to cudnn64_5.dll in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin.

7
  • Thanks Nova, this seemed to work. I also made sure to update my environment variables to match what Amar said lower in the comments.
    – snharan91
    May 2, 2017 at 1:01
  • There's an ongoing discussion on the topic on github. Make sure you follow the updates.
    – Nova
    May 3, 2017 at 8:48
  • 6
    I tried to rename from cudnn64_6.dll to cudnn64_5.dll and it didn't work. My mistake was that I downloaded cuDNN 6.0 instead of 5.1, and the requirements section in the installation guide says that it only supports version 5.1. It worked when I used the correct files. May 21, 2017 at 1:11
  • 3
    Indeed it needs to be version 5.1. No renaming is necessary.
    – Nickpick
    May 30, 2017 at 19:49
  • 2
    If you are using tensorflow 1.3 then you need to use cudnn65_6.dll github.com/tensorflow/tensorflow/issues/7705 Aug 20, 2017 at 7:02
8

You need to have CUDA_HOME leading to \cuda and %CUDA_HOME%\bin appended to your PATH. Also, tensorflow as of now only supports cudNN 5.1, please make sure you have that.

2
3

Have you tried turning it off and on again? Seriously, though. If you have your command line terminal running during the CUDA and cuDNN installs, the environment variables aren't refreshed until you close and re-open the terminal. I know it's simple, but I struggled for an hour before a simple restart solved that same import error.

2

I had the same problem running Windows 10, Anaconda 4.3.21 64bit, Python 3.5.3, and TensorFlow 1.2.0.
However, the issue was fixed by installing cuDNN v5.1 instead of v6.0 as proposed here https://stackoverflow.com/a/43566341/3830240

2
  • This is the best solution, as the "renamed DLL" solution (posted by Nova) will cause you to encounter a binary incompatibility issue later on.
    – rodamn
    Jul 5, 2017 at 7:36
  • 2
    If you are using tensorflow 1.3 then you want to use cuDNN 6.0 github.com/tensorflow/tensorflow/issues/7705 Aug 20, 2017 at 7:03
1

I still got the _pywrap_tensorflow_internal error after installing cuDNN 5.1 (yes, I had PATH set correctly). I had better luck installing tensorflow_gpu from this site. This requires cuDNN 6.0, not 5.1. Unfortunately they currently only have Tensorflow 1.1 for GPU systems.

0

I tried all the solutions here and it wasn't working for me. Check this link for the requirements and make sure you have the compatible versions. I also added all the cuDNN paths to my environment variables and also don't forget to copy the contents of lib,bin and include to the same folders inside your CUDA installation.

0

This is what worked for me. I referred to the Tensorflow website to find the currently supported CudaNN version. When I solved my issue, it was CudaNN 6.x. The latest version, in my case 7 DLL is not loaded by tensorflow, and if you try to rename it, it causes memory errors.

0

It should be noted that starting from version 1.0 up until version 1.2 Tensorflow needed Cuda8 and cudnnv5.1. Therefore You need to have cudnnv5.1 installed.
This question was asked on April 24 2017, This means the OP was trying to install version 1.1.0(at the time, the latest version) which at the time needed cudnnv5.1 and python3.5. So he needed to have cudnnv5.1 to fix his/her problem.

However, if you are trying to install the latest version of Tensorflow, that is anything greater than 1.3.0, you need cudnnv6.0 +.
If you are getting this error on 1.3.0, then it means you need cudnnv6.0. put that into your PATH and you will be fine.

0

It didn't work for me trying to change dll file versions. After struggling with tensorflow-gpu import error for a couple of weeks, I finally figured out that I needed to make respective directories(CUDA,cuDNN & CUPTI) matched to my %PATH% environment variable. I am using CUDA 9.0, cuDNN v7.0 with Tensorflow 1.11.

C:\> SET PATH=C:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v9.0\bin;%PATH% 

C:\> SET PATH=C:\Program Files\NVIDIA GPU
Computing Toolkit\CUDA\v9.0\extras\CUPTI\libx64;%PATH% 

C:\> SET PATH=C:\tools\cuda\bin;%PATH%

https://www.tensorflow.org/install/gpu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.