TensorFlow ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found
Asked Answered
B

3

2

System specifications:

  • Python==3.8.5
  • tensorflow==2.3.1

I am trying to import tensorflow... but I am getting import error. Please help me rectify the problem. I tried following...

pip uninstall tensorflow

and

pip install tensorflow

When I execute pip freeze I see the installed tensorflow package with specified version.
Error Message:

ImportError                               Traceback (most recent call last)
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     63   try:
---> 64     from tensorflow.python._pywrap_tensorflow_internal import *
     65   # This try catch logic is because there is no bazel equivalent for py_extension.

ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-d6579f534729> in <module>
----> 1 import tensorflow

~\anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     39 import sys as _sys
     40 
---> 41 from tensorflow.python.tools import module_util as _module_util
     42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
     43 

~\anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
     38 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
     39 
---> 40 from tensorflow.python.eager import context
     41 
     42 # pylint: enable=wildcard-import

~\anaconda3\lib\site-packages\tensorflow\python\eager\context.py in <module>
     33 from tensorflow.core.protobuf import config_pb2
     34 from tensorflow.core.protobuf import rewriter_config_pb2
---> 35 from tensorflow.python import pywrap_tfe
     36 from tensorflow.python import tf2
     37 from tensorflow.python.client import pywrap_tf_session

~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py in <module>
     26 
     27 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
---> 28 from tensorflow.python import pywrap_tensorflow
     29 from tensorflow.python._pywrap_tfe import *

~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     81 for some common reasons and solutions.  Include the entire stack trace
     82 above this error message when asking for help.""" % traceback.format_exc()
---> 83   raise ImportError(msg)
     84 
     85 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

ImportError: Traceback (most recent call last):
  File "C:\Users\user\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.```
Burkhart answered 21/11, 2020 at 14:19 Comment(0)
E
0

Use Anaconda to install Tensorflow,

Create separate environment for Tensorflow with Python 3.8

conda create --name tf python=3.8 tensorflow 
conda activate tf
Effloresce answered 14/12, 2020 at 9:49 Comment(2)
Thank you :) it's working. But I am not able to load TF in jupyter notebookBurkhart
Check in which environment Jupyter notebook is opened. If its different than the tf environment, fresh install Tensorflow there. ThanksEffloresce
A
0

I accidentally deleted this file. Uninstalling TensorFlow like pip uninstall tensorflow==2.3.0 and installing it again pip install tensorflow==2.3.0 resolved the issue. Dont forget to restart the kernal

Antre answered 14/8, 2021 at 15:45 Comment(0)
C
0

Adding my workaround/hack (TF 2.5.0), in case it helps someone:

In my case I already had a dozen of Visual C++ Redistributables installed ('05, '08, ... all the way to 2017) - but TF was still failing with the infamous ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found error. I didn't want to download and install another redistributable, just to get TF working. (Besides, I had already run into several posts, enough to raise doubt whether installing it would actually resolve the problem.)

According to this SO post, the offending failing _pywrap_tensorflow_internal.pyd is just another DLL; so I

  1. downloaded (just 468 KB) and ran Dependency Walker to detect which DLLs were requested by above PYD.
  2. in addition to the commonly mentioned vcruntime140.dll, the PYD was also depending on a vcruntime140_1.dll.
  3. vcruntime140.dll was available in C:/Windows/System32/ (checked using where vcruntime140.dll), but not vcruntime140_1.dll; so I ran a search on my system partition C: and found several copies of vcruntime140_1.dll at other places, mainly in my home dir's AppData/Local/ (user-installed apps).
  4. Almost all these apps were "trusted" ones (WhatsApp, MS Teams, ...) so I just copied vcruntime140_1.dll from one of them into C:/Windows/System32/ - and the error went away.

So if you get this error even when all documented requirements are fulfilled, do a bit of debugging to find the cause of the error. It will probably save you a good deal of frustration and wasted bandwidth.

Ceuta answered 7/11, 2021 at 16:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.