问题
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 :
If you dont have it Download Docker for windows (https://hub.docker.com/editions/community/docker-ce-desktop-windows/)
Run this command from you cmd :
docker pull tensorflow/tensorflow
check that you have the tensorflow image by running
docker images
command. you should get this output :
Open new project in pycharm
go to
Setting | Project | Project interpreter
Click on the three vertical dots to
Add
a new interpreteryou should get to this window (on the left click on "Docker"):
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 :
Install the Python extension
Install the Remote - Containers extension
Open the Command Pallette and type Remote-Containers, then select the Attach to Running Container... and selecet the running docker container
VS Code will restart and reload
On the Explorer sidebar, click the open a folder button and then enter /code (this will be loaded from the remote container)
On the Extensions sidebar, select the Python extension and install it on the container
Whenprompet on which interppreter to use, select /usr/local/bin/python
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