8

I installed CUDA 9.0 because without it, Tensorflow gives the error:

ImportError: Could not find 'cudart64_90.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable.

I have the path variable set to the bin directory of CUDA 9.0 installation, where the required DLL file is present. I tried setting it to its parent directory too. But it still gives me the same error. enter image description here


enter image description here

RodrikTheReader
  • 757
  • 1
  • 9
  • 22
  • Does that file exist? – RedEyed Jun 30 '18 at 05:24
  • Definitely yes. I double checked. – RodrikTheReader Jun 30 '18 at 05:26
  • Seems there are two versions of CUDA installed on the same system and there is a possibility of a version / name conflict which can confuse the loadlibrary calls used internally. Can you remove the other path and try again ? – Gautam Jun 30 '18 at 05:43
  • IDK... Try to add path inside script before importing tensorflow. `os.environ["PATH"].append("path/to/CUDA/v9/bin")` – RedEyed Jun 30 '18 at 05:50
  • @Gautam I removed v9.2 from PATH, but it didn't work. And it shouldn't matter since multiple CUDA versions can exist on the same system according to this post: https://devtalk.nvidia.com/default/topic/493290/multiple-cuda-versions-can-they-coexist-/ – RodrikTheReader Jun 30 '18 at 07:04

4 Answers4

23

I found the solution. And it was the good old advice - "Have you tried turning it off and on again?"

I restarted the computer, Tensorflow found cudart64_90.dll, but now it could not find cudnn64_7.dll. I'm providing the steps ahead to get rid of the issues I encountered.


If you've installed Tensorflow GPU version, you're likely to run into the problem mentioned in the post. Especially if you've not installed NVDIA development toolkits before. Follow these steps:

1. Install CUDA

Get it from here. Install only the version mentioned in Tensorflow's ImportError.

ImportError: Could not find 'cudart64_90.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.0 from this URL: https://developer.nvidia.com/cuda-toolkit

It explicitly tells you the version number. Initially, I installed CUDA 9.1 instead of 9.0, it didn't work. The installation on Windows is straight forward. Run the .exe, uncheck NVIDIA Geforce and other packages if you already have them installed.

2. Include CUDA path in PATH variable

Point it to the bin directory of your tensorflow installation. Check here if you don't know how to set the PATH variable. Now try importing Tensorflow, if it still doesn't work, try rebooting the system.

Now you will likely run into the error:

ImportError: Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 7 from this URL: https://developer.nvidia.com/cudnn

3. Install cuDNN

Once again, only install the version mentioned in the error.To get the installer, you need to have an NVIDIA developer account. If you don't have it, sign up and it will direct you to the link to download cuDNN. Select the version compatible with your CUDA version (it's in the package name). Download the zip archive. Extract it somewhere on your disk.

4. Include cuDNN path in PATH variable

Similar to step two. This time, point it to the bin directory in your extracted archive of cuDNN. Now import Tensorflow. Restart system if required.

It should now work.

RodrikTheReader
  • 757
  • 1
  • 9
  • 22
  • If the install of CUDA/CuDNN and PATH is ok, you just need to restart your shell or IDE, no need to restart the computer. – Ismael EL ATIFI Sep 21 '19 at 12:25
  • For part 1): If you get a suggestion to install CUDA and its version is 10.1,10.2, etc You will not get the cudart64_100.dll included, and instead you will get cudart64_101.dll/cudart64_102.dll etc. If it happens, see this answer: https://stackoverflow.com/a/58464975/5897324 – Richard Miller Dec 13 '19 at 02:06
2

When I reached to step 3, I copied and pasted the files inside the archive as in here

Copy <installpath>\cuda\bin\cudnn64_7.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin.

Copy <installpath>\cuda\ include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include.

Copy <installpath>\cuda\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64.
Salman Zafar
  • 3,844
  • 5
  • 20
  • 43
Azrai
  • 23
  • 7
1

I had the same problem for a couple hours as well. Just restarted my computer and that fixed the issue you were having, so give that a try.

-1

Always check the cuda version, in this case you have to install cuda version 9.0 this will create the cudart64_90.dll file in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin folder.

This will surely work.