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)
Links to this issue
- python - Cannot import Tensorflow for GPU on Windows 10 - Stack Overflow
- Installing TensorFlow on Windows (Python 3.6.x) - Stack Overflow
- On Windows, running "import tensorflow" generates No module named "_pywrap_tensorflow" error - Stack Overflow
- python - No Module Named '_pywrap_tensorflow_internal' - Stack Overflow
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 downloadcudnn-8.0-windows10-x64-v6.0for cuDNN 6.0, because it is looking forcudnn64_6.dll, notcudnn64_5.dllanymore!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 failedissue.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:
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-gpuOpen Anancoda prompt with administrative access and then run the following command.
conda install tensorflow-gpuThis will take care of everything paths, cuda, cudnn and dll files and will install everything in the particular place.
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.