On Windows, running “import tensorflow” generates

2018-12-31 09:06发布

On Windows, TensorFlow reports either or both of the following errors after executing an import tensorflow statement:

  • No module named "_pywrap_tensorflow"
  • DLL load failed.

标签: tensorflow
21条回答
何处买醉
2楼-- · 2018-12-31 09:50

For each Tensorflow's version, it requires different version of CuDnn. On www.tensorflow.org, they did not mentioned about that in installation guide!

My case use tensorflow version 1.3 which uses cuDNN 6. https://github.com/tensorflow/tensorflow/releases.

Please check your tensorfow version and cuDNN version if they are match together.

And please set path environment for cuDNN, if it still does not work, please check the comment from @Chris Han.

查看更多
素衣白纱
3楼-- · 2018-12-31 09:51

In my case the "cudnn64_6.dll" file in the /bin folder had to be renamed to "cudnn64_5.dll" for the error to go away. I easily spent two hours to figure this out, and I followed the official install guide to the letter. This is true for installation via pip (officially supported) and conda (community supported).

查看更多
孤独寂梦人
4楼-- · 2018-12-31 09:52

Either error indicates that your system has not installed MSVCP140.DLL, which TensorFlow requires.

To fix this error:

  1. Determine whether MSVCP140.DLL is in your %PATH% variable.
  2. If MSVCP140.DLL is not in your %PATH%, install the Visual C++ 2015 redistributable (x64 version), which contains this DLL.
查看更多
梦寄多情
5楼-- · 2018-12-31 09:54

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)
  • Make sure that ".DLL" is included in your PATHEXT variable
  • If you are using tensorflow 1.3 then you want to use cudnn64_6.dll github.com/tensorflow/tensorflow/issues/7705

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

查看更多
情到深处是孤独
6楼-- · 2018-12-31 09:54

The problem for me was the cuDNN library which didn't match the requirements of the graphics card. I downloaded the 6.0 version but for my GTX980ti but the recommended compute capability on the nvidia website was 5.1 ( http://developer.nvidia.com/cuda-gpus ) so I downloaded 5.1 and replaced the 6.0 version and as soon as I've done that it started working.

查看更多
余生请多指教
7楼-- · 2018-12-31 09:55

After much trial and error, and making sure VC++ 2015 Redistributable, cuDNN DLL and all other dependencies are accessible from PATH, it looks like Tensorflow GPU works only with Python 3.5.2 (as of this writing)

So if you're using Anaconda

  • conda create -n tensorflow-gpu python=3.5.2
  • activate tensorflow-gpu
  • pip install tensorflow-gpu

Then open the python interpreter and verify

>>> import tensorflow as tf
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

Found device 0 with properties:
name: GeForce 940M
major: 5 minor: 0
memoryClockRate (GHz) 1.176
pciBusID 0000:06:00.0
Total memory: 2.00GiB
Free memory: 1.66GiB

Credits: this neat guide

查看更多
登录 后发表回答