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:57

cuDNN causes my problem. PATH variable doesn't work for me. I have to copy the files in my cuDNN folders into respectful CUDA 8.0 folder structure.

查看更多
余生无你
3楼-- · 2018-12-31 09:59

I have Win7 Pro 64-bit on AMD cpu, no gpu. I was following the instructions under "Installing with native pip" at https://www.tensorflow.org/install/install_windows. The installation step went ok but the attempt to import tensorflow produced the infamous:

ImportError: No module named '_pywrap_tensorflow_internal'

This seems to be one of those situations where a lot of unrelated things can go wrong, depending on configuration, which all cascade through to the same error.

In my case, installing MSVCP140.DLL was the answer.

You have MSVCP140.DLL already if (a) you have a file C:\Windows\System43\MSVCP140.DLL, AND (b) if you have a 64 bit system, then you additionally have C:\Windows\SysWOW64\MSVCP140.DLL.

I installed it manually, which was unnecessary (the redistributable is not the whole Visual C++ development mess and isn't large). Use the link posted earlier in this thread to install it: Visual C++ 2015 redistributable.

Also, I recommend that you override the default install directory for Python and put it anywhere not under C:\Program Files, because Windows tries to write-protect files there, which causes problems later.

查看更多
泛滥B
4楼-- · 2018-12-31 09:59

I posted a general approach for troubleshooting the "DLL load failed" problem in this post on Windows systems.

  1. Use the DLL dependency analyzer Dependencies to analyze <Your Python Dir>\Lib\site-packages\tensorflow\python\_pywrap_tensorflow_internal.pyd and determine the exact missing DLL (indicated by a ? beside the DLL). The path of the .pyd file is based on the TensorFlow 1.9 GPU version that I installed. I am not sure if the name and path is the same in other TensorFlow versions.

  2. Look for information of the missing DLL and install the appropriate package to resolve the problem.

查看更多
听够珍惜
5楼-- · 2018-12-31 10:01

One may be tempted to keep the Powershell/cmd open on Windows. I've spent reasonable time till I decided to close and reopen my Powershell only to realize that I've done everything right.

查看更多
琉璃瓶的回忆
6楼-- · 2018-12-31 10:02

TensorFlow requires MSVCP140.DLL, which may not be installed on your system. To solve it open the terminal en type or paste this link:

C:\> pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.0-cp35-cp35m-win_amd64.whl 

Note this is to install the CPU-only version of TensorFlow.

查看更多
时光乱了年华
7楼-- · 2018-12-31 10:02

With TensorFlow release 1.3.0, you need to use Cudnn 6.0 instead of Cudnn 5.0 as Cudnn 5.0 is giving this error. Don't forget to add path variable to Cudnn 6.0 .With cudnn64_6.dll your Tensorflow will work fine. Read the link below. https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md#release-130

查看更多
登录 后发表回答