1

I was originally running Tensorflow using PyCharm. In PyCharm, the same phrase as the title did not appear. But after I switched to VS Code and installed Python extension, When I write and execute import tensorflow as tf, the error like the title appears repeatedly.

ImportError: Could not load dynamic library 'cudart64_110.dll'

Considering that there was no problem in PyCharm, it does not seem to be an environmental variable problem.

When I type the same command that was executed in VS Code in the command prompt window, another phrase appears,

"Connection failed because the target computer refused to connect."

My OS: Windows 10 I am using Anaconda, and I created a virtual environment. vscode ver : 1.53.2 tensorflow ver : 2.4.1 CUDA : 11.2 cudnn : 8.1

bad_coder
  • 11,289
  • 20
  • 44
  • 72
w r
  • 11
  • 1
  • 1
  • 2
  • I already tried to reboot and failed – w r Feb 15 '21 at 11:04
  • The version of Tensorflow you have has clearly been built for CUDA 11. It won't work with CUDA 11.2 – talonmies Feb 15 '21 at 11:58
  • If it is a version problem, it is normal that it does not work in pycharm, but it works without any problems in pycharm. – w r Feb 15 '21 at 12:24
  • @w r -Do you use the same python environment in VS Code as in pycharm? Have you tried to use cuda11.0 (and the supporting cudnn)? – Jill Cheng Feb 16 '21 at 04:48
  • 1
    Does this answer your question? [Working with Anaconda in Visual Studio Code](https://stackoverflow.com/questions/54828713/working-with-anaconda-in-visual-studio-code) – talonmies Feb 18 '21 at 04:52

3 Answers3

0

It is due to tensorflow GPU support. Tensorflow now comes with GPU support and the system need graphics support and CUDA, CUDU installations. If you missed CUDA installation then you will get the above message. The latest version of tensorflow sometimes won't run without CUDA.

Try to install tensorflow 1.15 and python 3.7.4

https://www.python.org/ftp/python/3.7.4/python-3.7.4-amd64.exe

pip install tensorflow==1.15

NB: Normally tensorflow will run without cuda but the message will always shown in the prompt.

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0

I would agree that this is due to your CUDA version, check the bottom of tensorflow GPU build config, it says for 2.4, you need CUDA 11.0 and cuDNN 8.0, which you have neither, in addition, you need MSVC 2019 to compile it.
Notice that for newer versions of tensorflow-gpu (>=2.3.0), conda will NOT download everything, you need to do them manually.
because it seems like all the evidence is pointing to GPU support problem, tensorflow-gpu might still run without using GPU, so it is possible that it was running on CPU when you use PyCharm,
I would suggest you double-check it runs as intended in PyCharm with

print(tf.config.list_physical_devices('GPU'))

or just simply reinstall everything

seermer
  • 571
  • 6
  • 12
  • import tensorflow as tf from tensorflow.python.client import device_lib print(device_lib.list_local_devices()) print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU'))) print(tf.config.list_physical_devices('GPU')) – w r Feb 15 '21 at 14:20
  • [name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { } incarnation: 17353097725904040844 , name: "/device:GPU:0" device_type: "GPU" memory_limit: 6932588160 locality { bus_id: 1 links { } } incarnation: 8560550394379888321 physical_device_desc: "device: 0, name: GeForce RTX 2070 SUPER, pci bus id: 0000:26:00.0, compute capability: 7.5" ] Num GPUs Available: 1 [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] – w r Feb 15 '21 at 14:21
  • It's coming out like the above in Pycharm, is there a problem with this? – w r Feb 15 '21 at 14:22
0

I copied "cudart64_110.dll" to the CUDA/v11.2/bin folder and it was resolved.

w r
  • 11
  • 1
  • 1
  • 2