Reputation: 734
I am running a Python file inside a virtualenv. This Python file imports keras, which imports tensorflow. Running the file gives this error:
(mnist) C:\Users\user1\Documents\GitHub\misc-python\mnist\src>python process_data.py
Traceback (most recent call last):
File "C:\Users\user1\Envs\mnist\lib\site-packages\keras\__init__.py", line 3, in <module>
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
File "C:\Users\user1\Envs\mnist\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\user1\Envs\mnist\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\user1\Envs\mnist\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
self_check.preload_check()
File "C:\Users\user1\Envs\mnist\lib\site-packages\tensorflow\python\platform\self_check.py", line 60, in preload_check
% " or ".join(missing))
ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environment variable. You may install these DLLs by downloading "Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019" for your platform from this URL: https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads
However msvcp140_1.dll exists in a directory which is in my PATH:
(mnist) C:\Users\user1\Documents\GitHub\misc-python\mnist\src>where msvcp140_1.dll
C:\Users\user1\Envs\mnist\Scripts\msvcp140_1.dll
C:\Windows\System32\msvcp140_1.dll
(mnist) C:\Users\user1\Documents\GitHub\misc-python\mnist\src>echo %PATH%
C:\Users\user1\Envs\mnist\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;...
This is what is installed in my virtualenv:
(mnist) C:\Users\user1\Documents\GitHub\misc-python\mnist\src>pip list
Package Version
---------------------- ---------
-ensorflow 2.2.0
absl-py 0.9.0
astunparse 1.6.3
bleach 1.5.0
cachetools 4.1.1
certifi 2020.6.20
chardet 3.0.4
cycler 0.10.0
gast 0.3.3
google-auth 1.19.2
google-auth-oauthlib 0.4.1
google-pasta 0.2.0
grpcio 1.30.0
h5py 2.10.0
html5lib 0.9999999
idna 2.10
importlib-metadata 1.7.0
Keras 2.4.3
Keras-Preprocessing 1.1.2
kiwisolver 1.2.0
Markdown 3.2.2
matplotlib 3.3.0
numpy 1.19.0
oauthlib 3.1.0
opt-einsum 3.2.1
Pillow 7.2.0
pip 20.1.1
protobuf 3.12.2
pyasn1 0.4.8
pyasn1-modules 0.2.8
pyparsing 2.4.7
python-dateutil 2.8.1
PyYAML 5.3.1
requests 2.24.0
requests-oauthlib 1.3.0
rsa 4.6
scipy 1.4.1
setuptools 49.2.0
six 1.15.0
tensorboard 2.2.2
tensorboard-plugin-wit 1.7.0
tensorflow 2.2.0
tensorflow-estimator 2.2.0
tensorflow-tensorboard 1.5.1
termcolor 1.1.0
urllib3 1.25.9
Werkzeug 1.0.1
wheel 0.34.2
wrapt 1.12.1
zipp 3.1.0
I am using Windows and I have tried rebooting. How can I get tensorflow to find this DLL?
Upvotes: 1
Views: 3270
Reputation: 543
If this happens to someone else: Just go to 'this pc' in the explorer and search for msvcp140_1.dll
.
Many python packages like PIL as well as other software come with this dll, so you likely already have a copy it on your computer, even without installing the "Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019" (which would require admin rights you might not have).
Just copy the path of any folder containing it and issue
import os
os.add_dll_directory("some/path/containing/the/dll/")
before
import tensorflow
Upvotes: 1
Reputation: 31
In the Windows 10, anaconda 4.9.2, after installing tensorflow 2.3, python 3.8 on conda, the same problem occurred, so I solved it via modifying ctypes.WinDLL(dll_name) to ctypes.WinDLL(dll_name, winmode=0) in self_check.py.
Upvotes: 3