Skip to content

TensorFlow 2.1: ImportError: DLL load failed: The specified module could not be found. #35749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nectario opened this issue Jan 10, 2020 · 16 comments
Assignees
Labels
TF 2.1 for tracking issues in 2.1 release type:build/install Build and install issues

Comments

@nectario
Copy link

nectario commented Jan 10, 2020

I am using

Python 3.76
TensorFlow 2.1
Installed using: pip install tensorflow
Processor: Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz, 2601 Mhz, 2 Core(s), 4 Logical Processor(s)
Laptop System Model: HP Spectre x360 Convertible
Reproduce: All I have to type is "import tensorflow as tf" and it fails.

Note: I also tried using tensorflow-cpu and still got the same issue.

Stack Trace:

>>> import tensorflow as tf
Traceback (most recent call last):
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Development\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Development\Python\Python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Development\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Development\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Development\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Development\Python\Python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 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.

<class 'ImportError'>, ImportError('Traceback (most recent call last):\n  File 
"C:\\Development\\Python\\Python37\\lib\\site-packages\\tensorflow_core\\python\\pywrap_tensorflow.py", line 58, in <module>\n    from 
tensorflow.python.pywrap_tensorflow_internal import *\n  File 
"C:\\Development\\Python\\Python37\\lib\\site-
packages\\tensorflow_core\\python\\pywrap_tensorflow_internal.py", line 28, in <module>\n    _pywrap_tensorflow_internal = swig_import_helper()\n  File 
"C:\\Development\\Python\\Python37\\lib\\site-
packages\\tensorflow_core\\python\\pywrap_tensorflow_internal.py", line 24, in
 swig_import_helper\n    _mod = imp.load_module(\'_pywrap_tensorflow_internal\', fp, pathname,
 description)\n  File "C:\\Development\\Python\\Python37\\lib\\imp.py", line 242, in load_module\n
    return load_dynamic(name, filename, file)\n  File 
"C:\\Development\\Python\\Python37\\lib\\imp.py", line 342, in load_dynamic\n    return 
_load(spec)\nImportError: DLL load failed: The specified module could not be found.\n\n\nFailed to
 load the native TensorFlow runtime.\n\nSee https://www.tensorflow.org/install/errors\n\nfor some
 common reasons and solutions.  Include the entire stack trace\nabove this error message when
 asking for help.'), <traceback object at 0x000001E0E43DCA48>



<em>Please make sure that this is a bug. As per our [GitHub Policy](https://github.com/tensorflow/tensorflow/blob/master/ISSUES.md), we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template</em>

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary):
  • TensorFlow version (use command below):
  • Python version:
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

You can collect some of this information using our environment capture
script
You can also obtain the TensorFlow version with: 1. TF 1.0: python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)" 2. TF 2.0: python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"

Describe the current behavior

Describe the expected behavior

Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

@galocen
Copy link

galocen commented Jan 11, 2020

I solved it today downloading and installing visual studio 2015-2019 x86 and x64 from here:
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Other solution is downgrading tensorflow to 2.0:
pip install tensorflow==2.0

I have Python 3.7.6, CUDA 10.1 and cuDNN for CUDA 10.1 and I have followed this requeriments:
https://www.tensorflow.org/install/gpu

I hope it works for you also!

@nectario
Copy link
Author

Thanks! That worked for me too!

@scottsaenz
Copy link

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

Wrong URL in markdown

@kiddojazz
Copy link

Best solution is just downgrading your tensorflow using
pip install tensorflow==2.0

@zayedrais
Copy link

It's work for me
pip install tensorflow==2.0
if you are using tensoflow-gpu
pip install --upgrade tensorflow-gpu==2.0

@Rialda
Copy link

Rialda commented Feb 7, 2020

I solved it today downloading and installing visual studio 2015-2019 x86 and x64 from here:
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Other solution is downgrading tensorflow to 2.0:
pip install tensorflow==2.0

I have Python 3.7.6, CUDA 10.1 and cuDNN for CUDA 10.1 and I have followed this requeriments:
https://www.tensorflow.org/install/gpu

I hope it works for you also!

Worked! :)

@Nitish-McQueen
Copy link

1.https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
2. download x64: vc_redist.x64.exe
3.install it.

It works.

@myself659
Copy link

1.https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
2. download x64: vc_redist.x64.exe
3.install it.

It works.

I will try this solution

@ReneWu1117
Copy link

1.https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
2. download x64: vc_redist.x64.exe
3.install it.

It works.

Thanks! It works for me!

@saif191020
Copy link

1.https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
2. download x64: vc_redist.x64.exe
3.install it.

It works.

Thanks!!! it works....

@mihaimaruseac
Copy link
Collaborator

Guys, please stop spamming with "it works" messages.

@ghost
Copy link

ghost commented Mar 7, 2020

i have python 3.6.0 , CUDA 10.2 and cuDNN and this fixed my problem :

  • downgrade to tensorflow-gpu 2.0 , and downgrade to protobuf 3.6.0 , install Microsoft Visual C++ Redistributable 2015-2019 x86 / x64

@mihaimaruseac
Copy link
Collaborator

@AhmedSheha0 that's a terrible advice.

Solution is given in #35749 (comment) (among other places). Let's not hide the solution with fake solutions and spam

@ghost
Copy link

ghost commented Mar 7, 2020

@AhmedSheha0 that's a terrible advice.

Solution is given in #35749 (comment) (among other places). Let's not hide the solution with fake solutions and spam

Im sharing what worked for me .. You can dislike my advice , or claim it didnt work for you , that's your right but it's not too nice of you to say it's a "terrible" advice and that I'm spamming and giving out fake solutions.

@mario-alvaro
Copy link

Tensorflow-gpu 2.1
Cuda 10.1
Python 3.6.5
cuDNN 7.6.4
Had the same problem, and upgrading Visual C totally worked for me.

@mihaimaruseac
Copy link
Collaborator

mihaimaruseac commented Mar 9, 2020

@AhmedSheha0 no, it is a terrible advice because 2.0 is not a LTS release hence after a year it will no longer receive security updates (just one example of why downgrading is not a solution)

Also, think how many people are notified and how many confusing "solutions" are in these threads. Also, notice how many people replied with the same spammy advice of "it works for me if you downgrade"

We could just lock thread to contributors to prevent such spam, but we rely on people who comment here to think before they write.

To conclude, the real solution is to install the latest MSVC redistributable from https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads and not to downgrade to 2.0

@tensorflow tensorflow locked as resolved and limited conversation to collaborators Mar 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TF 2.1 for tracking issues in 2.1 release type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests