问题
I am trying to install TensorFlow with GPU support on Windows 10, but I get an error (shown below) when importing it. The CPU version works fine.
I have
- installed
tensorflow-gpu
through pip - updated the NVidia drivers for my GTX 1050 with GeForce Experience
- installed CUDA 10.1 with NVidia's network installer
- installed cuDNN 7.5.0.56, taking care of copying every file in the right CUDA folder
- installed TensorRT 5.1.2.2 via the zip method and copied the relevant DLLs in CUDA again
This is the error:
> python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
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 "<stdin>", line 1, in <module>
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
My PATH environment variable (I removed all non-Microsoft and non-NVidia entries):
> echo $env:PATH.Split(';')
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp
C:\Program Files\Microsoft MPI\Bin\
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\dotnet\
C:\Program Files (x86)\dotnet\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.1\
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\lib64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include
C:\Program Files\TensorRT-5.1.2.2\lib
C:\Program Files\TensorRT-5.1.2.2\bin
C:\tools\cuda\bin
TensorRT is installed in C:\Program Files\TensorRT-5.1.2.2
.
Content of the CUDA bin
folder:
PS C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin> ls
Directory: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 18/04/2019 12:39 crt
-a---- 09/02/2019 06:57 202752 bin2c.exe
-a---- 09/02/2019 06:57 74850816 cublas64_10.dll
-a---- 09/02/2019 06:57 36055552 cublasLt64_10.dll
-a---- 09/02/2019 06:57 374272 cuda-memcheck.exe
-a---- 09/02/2019 06:57 4320256 cudafe++.exe
-a---- 09/02/2019 06:57 339968 cudart32_101.dll
-a---- 09/02/2019 06:57 408064 cudart64_101.dll
-a---- 18/04/2019 15:19 392566784 cudnn64_7.dll
-a---- 09/02/2019 06:57 115644416 cufft64_10.dll
-a---- 09/02/2019 06:57 225792 cufftw64_10.dll
-a---- 09/02/2019 06:57 4785664 cuinj64_101.dll
-a---- 09/02/2019 06:57 2074624 cuobjdump.exe
-a---- 09/02/2019 06:57 49030656 curand64_10.dll
-a---- 09/02/2019 06:57 171052032 cusolver64_10.dll
-a---- 09/02/2019 06:57 87930368 cusparse64_10.dll
-a---- 09/02/2019 06:57 285184 fatbinary.exe
-a---- 09/02/2019 06:57 1323008 gpu-library-advisor.exe
-a---- 09/02/2019 06:57 233472 nppc64_10.dll
-a---- 09/02/2019 06:57 10049024 nppial64_10.dll
-a---- 09/02/2019 06:57 3719680 nppicc64_10.dll
-a---- 09/02/2019 06:57 1003008 nppicom64_10.dll
-a---- 09/02/2019 06:57 7227904 nppidei64_10.dll
-a---- 09/02/2019 06:57 46016512 nppif64_10.dll
-a---- 09/02/2019 06:57 24603136 nppig64_10.dll
-a---- 09/02/2019 06:57 5848064 nppim64_10.dll
-a---- 09/02/2019 06:57 17426944 nppist64_10.dll
-a---- 09/02/2019 06:57 194560 nppisu64_10.dll
-a---- 09/02/2019 06:57 2610688 nppitc64_10.dll
-a---- 09/02/2019 06:57 8202240 npps64_10.dll
-a---- 09/02/2019 06:57 247296 nvblas64_10.dll
-a---- 09/02/2019 06:57 384000 nvcc.exe
-a---- 09/02/2019 06:57 310 nvcc.profile
-a---- 09/02/2019 06:57 22919168 nvdisasm.exe
-a---- 09/02/2019 06:57 149298688 nvgraph64_10.dll
-a---- 18/04/2019 16:46 131539456 nvinfer.dll
-a---- 18/04/2019 16:46 3663360 nvinfer_plugin.dll
-a---- 09/02/2019 06:57 5960192 nvlink.exe
-a---- 18/04/2019 16:46 4457472 nvonnxparser.dll
-a---- 18/04/2019 16:46 2447872 nvparsers.dll
-a---- 09/02/2019 06:57 4243456 nvprof.exe
-a---- 09/02/2019 06:57 221696 nvprune.exe
-a---- 09/02/2019 06:57 4580352 nvrtc-builtins64_101.dll
-a---- 09/02/2019 06:57 15659520 nvrtc64_101_0.dll
-a---- 09/02/2019 06:57 53 nvvp.bat
-a---- 09/02/2019 06:57 5838336 ptxas.exe
And the content of C:\tools
:
PS C:\tools> tree /F
Folder PATH listing
Volume serial number is 6A54-3EA7
C:.
└───cuda
│ NVIDIA_SLA_cuDNN_Support.txt
│
├───bin
│ cudnn64_7.dll
│
├───include
│ cudnn.h
│
└───lib
└───x64
cudnn.lib
回答1:
The problem was that I installed CUDA 10.1 instead of 10.0. TensorFlow isn't yet compatible with 10.1.
回答2:
Yes, some versions of TensorFlow doesn't support CUDA 10.1, in that case, CUDA 10.0 or lower version will solve your issue.
回答3:
This is how i resolved it, If you are using pip or pip3 you have less chance succeeding in first time.
- Uninstall Python,CUDA, CuNN, Tensorflow-gpu (if you already installed)
- Install ANACONDA or MINICONDA
- Open ANACONDA prompt and run following command:
conda create --name tf_gpu tensorflow-gpu
- This will create an environment tf_gpu whcih will install all compatible versions of Python, CUDA, CuNN and Tensorflow
- once all the packages installed open the ANACONDA prompt and type the following command
conda activate tf_gpu
- This will change the conda '(base)' to '(tf_gpu)' environment
- Then type python as usual to activate the python prompt
- If you want to deactivate the 'tf_gpu' environment
conda deactivate
来源:https://stackoverflow.com/questions/55749305/dll-load-failed-when-importing-tensorflow-with-gpu-support