tensorflow: ImportError: No module named '_pywrap_tensorflow' (MSVCP140.dll is present)

I installed the nightly build windows 64bit release of tensorflow from http://ci.tensorflow.org/view/Nightly/job/nightly-win/85/DEVICE=gpu,OS=windows/ using pip install in the Anaconda distribution of Python 3.5 (v4.1.1.0)

When I try to import tensorflow, I get the following error:

  File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", 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:\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 66, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow')
  File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "C:\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", 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:\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 66, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow')
  File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

Failed to load the native TensorFlow runtime. 

I checked the msvcp140.dll and it seems to be present in multiple locations of my %PATH% (in the anaconda folder, in system32, sysWOW64 and some other locations).

I also have environment variables setup for the CUDA path.

The issue filed here: https://github.com/tensorflow/tensorflow/issues/7529 is essentially the same as mine but the user resolved it by shifting development to a VPS running Ubuntu. It still doesn’t solve the problem though.

Any help would be appreciated! 😃

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 61 (16 by maintainers)

Most upvoted comments

I think it would be helpful if you specifically instruct users to move the cuDNN files (the dll, lib and the header) from the cuDNN extracted folder into: a.) A single folder containing all of these files and then add that folder to the %PATH% env variable. b.) move the dll into CUDA’s bin folder, the lib to CUDA’s lib folder and the header to CUDA’s include folder. Thanks for helping me through the whole process! It’s funny that the cuDNN path was an issue after I was so confident that wasn’t the case!

@mrry @Adrian-Steinert Thanks a lot for mentioning this!

I can confirm that at least for tensorflow version 1.3.0, we need to download cudnn-8.0-windows10-x64-v6.0 for cuDNN 6.0, because it is looking for cudnn64_6.dll, not cudnn64_5.dll anymore!

Wasted so much times due to this kind of hidden dll naming constraint, hope this can be helpful to other people who encountered loading dll failed issue.

The problem was the cuDNN Library for me - for whatever reason cudnn-8.0-windows10-x64-v6.0 was NOT working - I used cudnn-8.0-windows10-x64-v5.1 - ALL GOOD!

My setup working with Win10 64 and the Nvidia GTX780M:

  • Be sure you have the lib MSVCP140.DLL by checking your system/path - if not get it here
  • Run the windows installer for python 3.5.3-amd64 from here - DO NOT try newer versions as they probably won’t work
  • Get the cuDNN v5.1 for CUDA 8.0 from here - put it under your users folder or in another known location (you will need this in your path)
  • Get CUDA 8.0 x86_64 from here
  • Set PATH vars as expected to point at the cuDNN libs and python (the python path should be added during the python install)

If you run Windows 32 be sure to get the 32 bit versions of the files mentioned above.

Greetings,

i had the same issues described above:

Import errors as well as the case described 4 hours ago. What helped me in my case was in fact the cuDNN Version 6.

I am using python 3.6, CUDA 8, cuDNN 6 and tensorflow-gpu 1.3.0 on Windows 10 x64. For cuDNN I extracted the content of bin, include and lib to the respective folders in …\CUDA\v8.0\

I hope this resolves the issue for some of you guys.

EDIT: What may help as well to check if tensorflow really uses GPU is this solution on stackoverflow.

@DinoP I believe the released version of TensorFlow 1.3 depends on cuDNN 6, so it’s probably looking for cudnn64_6.dll.

I had the same issue, was able to solve it by using cuDNN 5.1 instead of 6.0. Is there a reason why 6.0 is not working? Does it have something to do with Windows? Just curious

@jcomfort4 I have solved the problem by the method discribed above. I guess the program just need a file like ‘cudnn64_5.dll’ and named ‘cudnn64_5.dll’. If you changed the name of ‘cudnn64_6.dll’ (which in cuDNN6.0) to ‘cudnn64_5.dll’ , it still worked.(But I haven’ t tested it for further use.) I advise you to check that you’ve put the file in right folder, because I noticed that you type them in wrong order. cudnn64_5.dll -----------------CUDA\v8.0\bin cudnn.h------------------------CUDA\v8.0\include cudnn.lib-----------------------CUDA\v8.0\lib\x64

I was having this issue and installing cuDNN 5.1 fixed it for me as well.

We are in the process of updating the website right now. Thank you for your patience and sorry for any inconvenience.

I spent forever on this issue only to find this open issue. Someone really needs to update the Windows guide

@guitarmind I can also confirm that this worked for me! This is huge, I spent ages and ages trying to solve this while having cudnn 5.1 because every single guide said that cudnn 6 doesn’t work, but in reality cudnn 6 is required for the current tensorflow-gpu 1.3.0

Woah! So it looks like cuDNN wasn’t setup properly. I put the dll, lib and .h file in CUDA’s respective folders. And it works.

To resolve the problem in windows 10, I did the following: 1. pip uninstall tensorflow-gpu

Open Anancoda prompt with administrative access and then run the following command. conda install tensorflow-gpu

This will take care of everything paths, cuda, cudnn and dll files and will install everything in the particular place.


Package plan for installation in environment C:\Anaconda3:

The following NEW packages will be INSTALLED:

    cudatoolkit:    8.0-1
    cudnn:          6.0-0
    libprotobuf:    3.2.0-vc14_0       [vc14]
    protobuf:       3.2.0-py35_0
    tensorflow-gpu: 1.1.0-np112py35_0
    vc:             14-0

The following packages will be UPDATED:

    astropy:        1.3.3-np111py35_0  --> 2.0.2-py35h891525e_4
    bottleneck:     1.2.1-np111py35_0  --> 1.2.1-np112py35_0
    h5py:           2.7.0-np111py35_0  --> 2.7.0-np112py35_0
    matplotlib:     2.0.2-np111py35_0  --> 2.0.2-np112py35_0
    numba:          0.33.0-np111py35_0 --> 0.33.0-np112py35_0
    numexpr:        2.6.2-np111py35_0  --> 2.6.2-np112py35_0
    numpy:          1.11.3-py35_0      --> 1.12.1-py35_0
    pandas:         0.20.1-np111py35_0 --> 0.20.3-py35_0
    pytables:       3.2.2-np111py35_4  --> 3.2.2-np112py35_4
    pywavelets:     0.5.2-np111py35_0  --> 0.5.2-np112py35_0
    scikit-image:   0.13.0-np111py35_0 --> 0.13.0-np112py35_0
    scikit-learn:   0.18.1-np111py35_1 --> 0.19.0-np112py35_0
    scipy:          0.19.0-np111py35_0 --> 0.19.1-np112py35_0
    statsmodels:    0.8.0-np111py35_0  --> 0.8.0-np112py35_0
    vs2015_runtime: 14.00.23026.0-0    --> 14.0.25420-0
    werkzeug:       0.11.4-py35_0      --> 0.12.2-py35_0

Proceed ([y]/n)? y

cudatoolkit-8. 100% |###############################| Time: 0:00:03 103.92 MB/s
cudnn-6.0-0.ta 100% |###############################| Time: 0:00:01  61.40 MB/s
vs2015_runtime 100% |###############################| Time: 0:00:00  50.37 MB/s
vc-14-0.tar.bz 100% |###############################| Time: 0:00:00 117.44 kB/s
libprotobuf-3. 100% |###############################| Time: 0:00:00  59.48 MB/s
numpy-1.12.1-p 100% |###############################| Time: 0:00:00  54.71 MB/s
werkzeug-0.12. 100% |###############################| Time: 0:00:00  32.00 MB/s
bottleneck-1.2 100% |###############################| Time: 0:00:00   6.92 MB/s
h5py-2.7.0-np1 100% |###############################| Time: 0:00:00  39.03 MB/s
numba-0.33.0-n 100% |###############################| Time: 0:00:00  54.14 MB/s
numexpr-2.6.2- 100% |###############################| Time: 0:00:00  15.75 MB/s
protobuf-3.2.0 100% |###############################| Time: 0:00:00  31.49 MB/s
pywavelets-0.5 100% |###############################| Time: 0:00:00  52.60 MB/s
scipy-0.19.1-n 100% |###############################| Time: 0:00:00  61.34 MB/s
astropy-2.0.2- 100% |###############################| Time: 0:00:00  59.28 MB/s
pandas-0.20.3- 100% |###############################| Time: 0:00:00  52.79 MB/s
pytables-3.2.2 100% |###############################| Time: 0:00:00  42.35 MB/s
scikit-learn-0 100% |###############################| Time: 0:00:00  51.41 MB/s
tensorflow-gpu 100% |###############################| Time: 0:00:01  36.20 MB/s
matplotlib-2.0 100% |###############################| Time: 0:00:00  56.54 MB/s
statsmodels-0. 100% |###############################| Time: 0:00:00  56.49 MB/s
scikit-image-0 100% |###############################| Time: 0:00:00  49.93 MB/s

I just wrestled with this for a couple hours (Windows 10, Anaconda 4.4.0 64 bit). I had been trying to install tensorflow-gpu using pip with no success. I followed all the guides I could find, tried using Python 3.5.3, installed cudnn 5.1 and 6.0, tried different combinations using conda environments, and still ran into the same error.

I found that installing via conda rather than pip worked the first time. Conda installed cudatoolkit, cudnn, libprotobuf, and protobuf and updated itself and vs2015_runtime.

Apparently conda is better at putting all this stuff in the right place than I am. Praise conda.

@av8ramit Can we modify the webpage to point to cudnn 6?

@Innixma I did exactly the same…tried to reinstall python, CUDA, cuDNN, check environment variables so many times.

Totally misled by all public guides until I saw this issue page. Could anyone update the official installation guide of TensorFlow to mention about this for the updates after tensorflow-gpu 1.3.0?

Ok, so i think i finally found the solution to my problem. I’ve followed every guide out there, so was just about to give up.

First of all, thanks @mrry creating this script: https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c It made me aware of my problem. It told me that cudart64_80.dll was missing.

So when going to the Nvidia download page, you get presented with 2 downloads, Base installer and “Patch 2”. Because Patch 2 was a larger file size than base I thought this version contained everything. Also “Patch 2” installs with no problems, even though Base installation is missing.

So it turned out that I missed the Base installation and didn’t have CUDA properly installed, only the Patch.

Hope this helps the others.

I had the same problem. Followed your instruction (b) and the problem is solved! Thanks a lot!

Thank you SiddGururani, copying the cuDNN dll, lib, and header to the CUDA folder’s respective subfolders worked for me as well. I have Cuda 8.0 and cuDNN 5.1, and (native) pip install tensorflow-gpu had claimed success, but I was still having this problem.

I have similar problem. After installation of MS VC++ 2015 Redistributable Update 3 x64, the problem still exists. I have tried the above method. However, it still does not work. Can anyone help? Thank you.

My environment: Windows 7 64 bit Python 3.5.3 Tensorflow GPU 1.10rc1 Cuda 8.0 Cudnn 6.0

---------------Update-------------------- It’s CuDNN 6’s problem, which does NOT work on my environment! When I switch to Cudnn5.1, everything works fine! Thanks to @ZacDiggum who found the problem at 9066

Here are the error message when I “import tensorflow”:

Traceback (most recent call last): File “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow_internal.py”, line 18, in swig_import_helper return importlib.import_module(mname) File “D:\Programs\Python35\lib\importlib_init_.py”, line 126, in import_mod ule 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 914, 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 “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow.py”, line 41, in from tensorflow.python.pywrap_tensorflow_internal import * File “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow_internal.py”, line 21, in _pywrap_tensorflow_internal = swig_import_helper() File “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow_internal.py”, line 20, in swig_import_helper return importlib.import_module(‘pywrap_tensorflow_internal’) File “D:\Programs\Python35\lib\importlib_init.py”, line 126, in import_mod ule return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named ‘_pywrap_tensorflow_internal’

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “”, line 1, in File “D:\Programs\Python35\lib\site-packages\tensorflow_init_.py”, line 24, in from tensorflow.python import * File “D:\Programs\Python35\lib\site-packages\tensorflow\python_init_.py”, l ine 51, in from tensorflow.python import pywrap_tensorflow File “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow.py”, line 52, in raise ImportError(msg) ImportError: Traceback (most recent call last): File “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow_internal.py”, line 18, in swig_import_helper return importlib.import_module(mname) File “D:\Programs\Python35\lib\importlib_init_.py”, line 126, in import_mod ule 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 914, 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 “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow.py”, line 41, in from tensorflow.python.pywrap_tensorflow_internal import * File “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow_internal.py”, line 21, in _pywrap_tensorflow_internal = swig_import_helper() File “D:\Programs\Python35\lib\site-packages\tensorflow\python\pywrap_tensorfl ow_internal.py”, line 20, in swig_import_helper return importlib.import_module(‘pywrap_tensorflow_internal’) File “D:\Programs\Python35\lib\importlib_init.py”, line 126, in import_mod ule 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.