Tensorflow : ImportError: DLL load failed

我们两清 提交于 2021-02-11 13:55:26

问题


I am using Windows 10, Python 3.7.8 and PyCharm.

First, I installed Python 3.7.8. Then I installed PyCharm.

I am trying to run Python code, to be specific Tensorflow code. I follow these instructions here: https://www.tensorflow.org/site-assets/downloads/marketing/cert/Setting_Up_TF_Developer_Certificate_Exam.pdf Page 4-8.

As in the instructions I create a new PyCharm project:

Then in the preferences for this Project, choosing Python Interpreter I install the following packages:

  • tensorflow
  • tensorflow-datasets
  • numpy
  • pillow
  • urllib3

All get installed succesfully:

Then I create a new Python file:

I run the following code:

import tensorflow as tf
print(tf.version)

However, I get error(s): "ImportError: DLL load failed: The specified module could not be found"

How can I fix this?


回答1:


SHORT ANSWER

According to this thread : https://github.com/tensorflow/tensorflow/issues/35618#issuecomment-596631286

downloading that lastest microsoft redistributable C++ from here :

https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

will solve your problem

EXTRA 1 : Use Docker as a Python Interpreter in Pycharm

Pycharm has a usefull tool that I personally use all the time : Docker as an interpreter.

This implies to install Docker but once you got it, you can download pretty much all the images with dependecies pre-installed and ready for work !

In your case :

  1. If you dont have it Download Docker for windows (https://hub.docker.com/editions/community/docker-ce-desktop-windows/)

  2. Run this command from you cmd : docker pull tensorflow/tensorflow

  3. check that you have the tensorflow image by running docker images command. you should get this output :

  1. Open new project in pycharm

  2. go to Setting | Project | Project interpreter

  3. Click on the three vertical dots to Add a new interpreter

  4. you should get to this window (on the left click on "Docker"):

  5. click on "OK"

And Let's code !

Now if you need another big dependecy like this one, you can always reproduce those steps with the specific dependency image from docker hub

For further details, here is the official tutorial from JetBrains : How to make Docker container as an interpreter in PyCharm

EXTRA 2 : Use Docker as a Python Interpreter in VSCode

For some of users that using python in VSCode (I personally don't), I've found those steps to achieve the same configuration (Docker as python interpreter) in VSCode :

  1. Install the Python extension

  2. Install the Remote - Containers extension

  3. Open the Command Pallette and type Remote-Containers, then select the Attach to Running Container... and selecet the running docker container

  4. VS Code will restart and reload

  5. On the Explorer sidebar, click the open a folder button and then enter /code (this will be loaded from the remote container)

  6. On the Extensions sidebar, select the Python extension and install it on the container

  7. Whenprompet on which interppreter to use, select /usr/local/bin/python

  8. Open the Command Pallette and type Python: Configure Tests, then select the unittest framework

    Source for this part : Setting Up a Python Remote Interpreter Using Docker



来源:https://stackoverflow.com/questions/62758688/tensorflow-importerror-dll-load-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!