Skip to content
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

Installation issue with Tensorflow-cpu, no module named '_pwyrap_tensorflow_internal' #22512

Closed
Overdrivr opened this issue Sep 25, 2018 · 72 comments

Comments

@Overdrivr
Copy link

Overdrivr commented Sep 25, 2018

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 server in desktop mode
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: NA
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): tensorflow-gpu 1.10.0
  • Python version: Anaconda x64 3.6
  • Bazel version (if compiling from source): NA
  • GCC/Compiler version (if compiling from source): NA
  • CUDA/cuDNN version: 9.0/7.0
  • GPU model and memory: Q4000
  • Exact command to reproduce: N/A

Describe the problem

  1. Create a python application that imports tensorflow-gpu
  2. Package the application with pyinstaller
  3. Start the generated executable, that crashes while trying to import tensorflow.

The error trace is this:

Traceback (most recent call last):
  File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
  File "c:\users\paperspace\.virtualenvs\***-ecouzwts\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>
  File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
  File "importlib\__init__.py", line 126, in import_module
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

On the other hand, doing the same process with tensorflow(-cpu) works fine.

I ruled out CUDA/cuDNN installation issue, because if I run my python application using python, it works fine with the GPU version.

I have tried checking at the .exe with dependency_walker, but appart from false-positive missing API-MS-* and EXT-MS-* DLLs, I don't see anything obvious.

So I'm stuck here.
What discrepancy could create an import issue with tensorflow-gpu and not with tensorflow-cpu ?

@tensorflowbutler tensorflowbutler added the stat:awaiting response Status - Awaiting response from author label Sep 26, 2018
@tensorflowbutler
Copy link
Member

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
Exact command to reproduce

@Overdrivr
Copy link
Author

I've updated the form accordingly

@Overdrivr
Copy link
Author

Overdrivr commented Sep 26, 2018

@ymodak I have made some progress. It turns out, I was building tensorflow from an Anaconda shell. I removed Anaconda and installed standard python 3.6.6 64 bits.

By doing so, the initial problem went away.
Executable runs fine on the build machine.
However, if I transfer the standalone application to another machine, it fails with the following error:

Traceback (most recent call last):
  File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-ecouzwts\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
  File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>
  File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
  File "importlib\__init__.py", line 126, in import_module
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "nxt\nxt.py", line 2, in <module>
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-ecouzwts\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
  File "site-packages\tensorflow\__init__.py", line 22, in <module>
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-ecouzwts\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
  File "site-packages\tensorflow\python\__init__.py", line 49, in <module>
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-ecouzwts\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
  File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
ImportError: Traceback (most recent call last):
  File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-ecouzwts\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
  File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>
  File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
  File "importlib\__init__.py", line 126, in import_module
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

Here is the code to reproduce:

import tensorflow as tf

def main():	
	hello = tf.constant('hello TF')
	sess = tf.Session()
	print(sess.run(hello))

if __name__ == '__main__':
    main()

Steps to reproduce:

  1. Run the program with python 3.6 and tensorflow-gpu 1.10.0. Works ok.
  2. Package into a standalone with PyInstaller
  3. Run the executable. Works ok.
  4. Move the folder containing the executable and all dependencies to another machine.
  5. Run the executable. Fails with error above.

@Overdrivr
Copy link
Author

I finally managed to catch the exception happening at import time, application is raising EXCEPTION_ILLEGAL_INSTRUCTION.

exception_illegal_instruction

Could this be related to AXV instructions not supported ? The processor of the VM is an Intel Xeon E5-2623 v4 that apparently supports AVX2.

@ymodak ymodak assigned wt-huang and unassigned ymodak Sep 26, 2018
@wt-huang
Copy link

@Overdrivr This is not a bug. You can run some sanity checks on the second machine to make sure the environment is set up correctly and dependencies are installed properly.

@Overdrivr
Copy link
Author

You're correct, there is a configuration issue on the second machine.

I have installed python 3.6.6 on it, created a new virtual env, only containing tensorflow, and can reproduce the issue.

What puzzles me is that I have installed tensorflow-cpu on it, and I still get _pywrap_tensorflow_internal not found (And it's not the first time I've installed TF on a machine, I've done it for CPU and GPU version a good dozen of times).

I have ran the following sanity check (updated for tensorflow 1.10.0, Cuda 9.0, cuDNN 7.0.X):

import ctypes
import imp
import sys
from ctypes.util import find_library

def main():
    check()

def check():
    try:
        import tensorflow as tf
        print("TensorFlow successfully installed.")
        if tf.test.is_built_with_cuda():
            print("The installed version of TensorFlow includes GPU support.")
        else:
            print("The installed version of TensorFlow does not include GPU support.")
            #sys.exit(0)
    except ImportError as e:
        print("ERROR: Failed to import the TensorFlow module.")
        print('Reason: {}'.format(e))

    candidate_explanation = False

    python_version = sys.version_info.major, sys.version_info.minor
    print("- Python version is %d.%d." % python_version)
    if not (python_version == (3, 5) or python_version == (3, 6)):
        candidate_explanation = True
        print("- The official distribution of TensorFlow for Windows requires "
          "Python version 3.5 or 3.6.")

    try:
        _, pathname, _ = imp.find_module("tensorflow")
        print("- TensorFlow is installed at: %s" % pathname)
    except ImportError:
        candidate_explanation = False
        print("""- No module named TensorFlow is installed in this Python environment. You may
install it using the command `pip install tensorflow`.""")

    try:
        msvcp140 = ctypes.WinDLL("msvcp140.dll")
        msvcp140_path = find_library("msvcp140.dll")
        print('- msvcp140.dll Found at {}'.format(msvcp140_path))
    except OSError:
        candidate_explanation = True
        print("""
- Could not load 'msvcp140.dll'. You may install this DLL by downloading Microsoft Visual
  C++ 2015 Redistributable Update 3 from this URL:
  https://www.microsoft.com/en-us/download/details.aspx?id=53587""")

    try:
        cudart64_90 = ctypes.WinDLL("cudart64_90.dll")
        cudart64_90_path = find_library("cudart64_90.dll")
        print('- Cuda 9.0 found at {}'.format(cudart64_90_path))
        # TODO: Look for version.txt file in CUDA path
    except OSError:
        candidate_explanation = True
        print("""
- Could not load 'cudart64_90.dll'. Download and install CUDA 9.0 from
  this URL: https://developer.nvidia.com/cuda-toolkit""")

    try:
        nvcuda = ctypes.WinDLL("nvcuda.dll")
        nvcuda_path = find_library("nvcuda.dll")
        print('- nvcuda.dll found at {}'.format(nvcuda_path))
    except OSError:
        candidate_explanation = True
        print("""
- Could not load 'nvcuda.dll'. The GPU version of TensorFlow requires that
  this DLL be installed in a directory that is named in your %PATH%
  environment variable. Typically it is installed in 'C:\Windows\System32'.
  If it is not present, ensure that you have a CUDA-capable GPU with the
  correct driver installed.""")

    cudnn7_found = False
    try:
        cudnn7 = ctypes.WinDLL("cudnn64_7.dll")
        cudnn7_path = find_library("cudnn64_7.dll")
        print("- cuDNN Found at {}".format(cudnn7_path))
        cudnn7_found = True
    except OSError:
        candidate_explanation = True
        print("""
- Could not load 'cudnn64_7.dll'. The GPU version of TensorFlow
  requires that this DLL be installed in a directory that is named in
  your %PATH% environment variable. Note that installing cuDNN is a
  separate step from installing CUDA, and it is often found in a
  different directory from the CUDA DLLs. You may install the
  necessary DLL by downloading cuDNN 7.0 for Cuda 9.0 from this URL:
  https://developer.nvidia.com/cudnn""")

    if not candidate_explanation:
        print("""
- All required DLLs appear to be present. Please open an issue on the
  TensorFlow GitHub page: https://github.com/tensorflow/tensorflow/issues""")

    sys.exit(-1)


if __name__ == '__main__':
    main()

Output:

ERROR: Failed to import the TensorFlow module.
Reason: Traceback (most recent call last):
  File "C:\Users\Paperspace\.virtualenvs\test-tf-vXVQRlro\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\Paperspace\.virtualenvs\test-tf-vXVQRlro\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Paperspace\.virtualenvs\test-tf-vXVQRlro\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Paperspace\.virtualenvs\test-tf-vXVQRlro\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Paperspace\.virtualenvs\test-tf-vXVQRlro\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Users\Paperspace\.virtualenvs\test-tf-vXVQRlro\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
- Python version is 3.6.
- TensorFlow is installed at: C:\Users\Paperspace\.virtualenvs\test-tf-vXVQRlro\lib\site-packages\tensorflow
- msvcp140.dll Found at C:\Windows\system32\msvcp140.dll
- Cuda 9.0 found at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\cudart64_90.dll
- nvcuda.dll found at C:\Windows\system32\nvcuda.dll
- cuDNN Found at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\cudnn64_7.dll

- All required DLLs appear to be present. Please open an issue on the
  TensorFlow GitHub page: https://github.com/tensorflow/tensorflow/issues

Basically, the sanity check does not highlight any error, yet there seems to be an issue loading some DLL. This is very weird, because I have installed TF-cpu and GPU on another machine with exactly the same specs two hours before that one (They are both freshly created machines on a cloud provider with the same base Windows 10 image).

@Overdrivr Overdrivr changed the title Packaging issues with tensorflow-gpu Installation issue with Tensorflow-cpu, no module named '_pwyrap_tensorflow_internal' Sep 27, 2018
@Overdrivr
Copy link
Author

I have tried TF 1.5 and it solves the issue. TF can be imported just fine. So, clearly, it has be an issue with AVX.

But it is stated here (and everywhere else) that the Xeon E5-2623 v4 supports AVX2, so I guess it should support AVX too, right ?

To be sure, I wrote a small script that fetches CPUID and checks if the hardware supports AVX.
Install cpuid to run it.

from cpuid import *

def _is_set(id, reg_idx, bit):
    regs = cpuid(id)

    if (1 << bit) & regs[reg_idx]:
        return "Yes"
    else:
        return "--"

print("Vendor ID         : %s" % cpu_vendor())
print("CPU name          : %s" % cpu_name())
print("Microarchitecture : %s%s" % cpu_microarchitecture())
print("Vector instructions supported:")
print("SSE       : %s" % _is_set(1, 3, 25))
print("SSE2      : %s" % _is_set(1, 3, 26))
print("SSE3      : %s" % _is_set(1, 2, 0))
print("SSSE3     : %s" % _is_set(1, 2, 9))
print("SSE4.1    : %s" % _is_set(1, 2, 19))
print("SSE4.2    : %s" % _is_set(1, 2, 20))
print("SSE4a     : %s" % _is_set(0x80000001, 2, 6))
print("AVX       : %s" % _is_set(1, 2, 28))
print("AVX2      : %s" % _is_set(7, 1, 5))
print("BMI1      : %s" % _is_set(7, 1, 3))
print("BMI2      : %s" % _is_set(7, 1, 8))

And this is what I get:

Vendor ID         : GenuineIntel
CPU name          : Intel(R) Xeon(R) CPU E5-2623 v4 @ 2.60GHz
Microarchitecture : broadwellnoavx
Vector instructions supported:
SSE       : Yes
SSE2      : Yes
SSE3      : Yes
SSSE3     : Yes
SSE4.1    : Yes
SSE4.2    : Yes
SSE4a     : --
AVX       : --
AVX2      : --
BMI1      : Yes
BMI2      : Yes

Just the name of the micro-architecture is pretty self-explanatory.
Not only does he not support AVX2, he does not even support AVX1.

I would like to give a big THANKS to intel for advertising their processor to support AVX when they clearly don't (and for wasting our time).

@Overdrivr
Copy link
Author

While we're at it, I'm getting the same problem with tensorflow-cpu... on another freshly created machine.. that supports AVX. Fun ride.

Emotionnal rollercoaster

I'm leaving this here for documentation, it might help others.

In my production virtualenv with tensorflow-cpu + a bunch of other packages, I get the following error (the output comes from a tensorflow-install-checker tool that I will release in public domain):

INFO - Vendor ID         : GenuineIntel
INFO - CPU name          : Intel(R) Xeon(R) CPU E5-2623 v4 @ 2.60GHz
INFO - Microarchitecture : broadwell
OK  - Your processor supports AVX instructions
ERR - Failed to import the TensorFlow module.
Traceback (most recent call last):
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
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 "c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
OK  - TensorFlow found at: c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\site-packages\tensorflow
OK  - msvcp140.dll found at: c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\site-packages\scipy\extra-dll\msvcp140.dll
OK  - Cuda 9.0 found at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\cudart64_90.dll
OK  - nvcuda.dll found at C:\Windows\system32\nvcuda.dll
OK  - cuDNN Found at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\cudnn64_7.dll

In another virtualenv with only tensorflow-cpu, I get this one:

Traceback (most recent call last):
  File "C:\Users\Paperspace\.virtualenvs\test_tf--gQQvE-L\lib\site-packages\tensorflow\python\platform\self_check.py", line 47, in preload_check
    ctypes.WinDLL(build_info.msvcp_dll_name)
  File "C:\Program Files\Python36\Lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Paperspace\.virtualenvs\test_tf--gQQvE-L\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\Paperspace\.virtualenvs\test_tf--gQQvE-L\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Paperspace\.virtualenvs\test_tf--gQQvE-L\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
    self_check.preload_check()
  File "C:\Users\Paperspace\.virtualenvs\test_tf--gQQvE-L\lib\site-packages\tensorflow\python\platform\self_check.py", line 55, in preload_check
    % build_info.msvcp_dll_name)
ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. You may install this DLL by downloading Visual C++ 2015 Redistributable Update 3 from this URL: https://www.microsoft.com/en-us/download/details.aspx?id=53587

Hum weird right ? Let's summarize:

  • In the first env, msvcp140.dll is found, but TF fails to load
  • In the second env, msvcp140.dll is missing

If you look closely, the msvcp140.dll found in the first env does not come from system32 folder.
It comes from scipy (c:\users\paperspace\.virtualenvs\******-jrq2aiwp\lib\site-packages\scipy\extra-dll\msvcp140.dll).
Scipy is (to solve other issues) releasing msvcp140.dll in their extra-dll folder. This folder ends up in the PATH, and the dll in question picked up by the library finder.

Now, why that's a problem:

  • For machines that already have this DLL in system32 folder, it's fine because system path takes precedence over user path.
  • For machines without this DLL, instead of having TF crash with DLL missing, it crashes with some cryptic _pywrap_tensorflow_internal... error, most likely because the DLL found in scipy is different and not compatible that the latest installed by Microsoft Visual C++ 2015 Redistributable Update 3 RC. The workaround is then to simply install Microsoft Visual C++ 2015 Redistributable 64 bits. This way, the DLL is installed in system32 folder and takes precedences over the one installed by scipy.

After doing so on my VM, importing TF in both virtualenvs now runs properly. 🥂

INFO - Vendor ID         : GenuineIntel
INFO - CPU name          : Intel(R) Xeon(R) CPU E5-2623 v4 @ 2.60GHz
INFO - Microarchitecture : broadwell
OK  - Your processor supports AVX instructions
OK  - TensorFlow is functional.
ERR - TensorFlow does not include GPU support.
OK  - TensorFlow found at: c:\users\paperspace\.virtualenvs\nexture-studio-dist-jrq2aiwp\lib\site-packages\tensorflow
OK  - msvcp140.dll found at: C:\Windows\system32\msvcp140.dll
OK  - Cuda 9.0 found at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\cudart64_90.dll
OK  - nvcuda.dll found at C:\Windows\system32\nvcuda.dll
OK  - cuDNN Found at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\cudnn64_7.dll

Maybe it might be worth mentioning it in the install docs.

@gunan
Copy link
Contributor

gunan commented Sep 27, 2018

@lamberta Can we add this requirement to our windows installation docs?

For machines without this DLL, instead of having TF crash with DLL missing, it crashes with some cryptic _pywrap_tensorflow_internal... error, most likely because the DLL found in scipy is different and not compatible that the latest installed by Microsoft Visual C++ 2015 Redistributable Update 3 RC. The workaround is then to simply install Microsoft Visual C++ 2015 Redistributable 64 bits. This way, the DLL is installed in system32 folder and takes precedences over the one installed by scipy.

@lamberta
Copy link
Member

@gunan I can highlight the need to install Microsoft Visual C++ 2015 Redistributable and to make sure the DLL is installed in the system32 folder.

Can also add the error message to this page: https://www.tensorflow.org/install/errors (and link to this issue).

But is this something tensorflow can detect and provide a more useful error message? "Can not find msvcp140.dll in system32 directory" (or something)

@gunan
Copy link
Contributor

gunan commented Sep 27, 2018

Certainly. Both are things we need to do.

@tensorflowbutler
Copy link
Member

Nagging Assignee @wt-huang: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

@wt-huang
Copy link

Closing this issue as the PR is merged.

@tamamjerbi
Copy link

PLEASE HELP!!!
I've tried everything, can't understand why on earth is this hapenning!!
my system instructions set:-----------------------------------------
Instructions sets | MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, EM64T, VT-x, AES, AVX, AVX2, FMA3

Win10-64bit
Core i5 8250U
and using tensorflow cpu 1.12

what I've tried so far
downgrading Tensorflow to 1.5 and 1.9
Installing C++ build tools
I've already latest C++ redist 2017
.................................................................................
don't know what to do else!!!!

Error reproduce on importing tensorflow

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python_init_.py", line 59, in
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in
from google.protobuf import descriptor as _descriptor
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\google\protobuf\descriptor.py", line 47, in
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.

please help!!!

@Overdrivr
Copy link
Author

It's because it's not TF that fails to load, it's protobuf: protocolbuffers/protobuf#5046 (comment)

Apparently, downgrading to protobuf 3.6.0 (most likely you have 3.6.1) does the trick

@praneetmehta
Copy link

It's because it's not TF that fails to load, it's protobuf: protocolbuffers/protobuf#5046 (comment)

Apparently, downgrading to protobuf 3.6.0 (most likely you have 3.6.1) does the trick

The problem exists for every version of tensorflow 1.5 - 1.12 (cpu). But downgrading protobuf from 3.6.1 to 3.6.0 does the trick. @Overdrivr thanks for the solution

@kumarrajesh996
Copy link

import keras
Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 343, 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 "", line 1, in
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_init_.py", line 3, in
from . import utils
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils_init_.py", line 6, in
from . import conv_utils
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\conv_utils.py", line 9, in
from .. import backend as K
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend_init_.py", line 89, in
from .tensorflow_backend import *
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in
import tensorflow as tf
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python_init_.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 343, 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.

Please help me with this error

@thisisreallife
Copy link

(3) E:\GitHub\3\EasyRL>python demo/run_dqn_on_pong.py
Traceback (most recent call last):
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Travis\AppData\Roaming\Python\Python36\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:\ProgramData\Anaconda3\envs\3\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\ProgramData\Anaconda3\envs\3\lib\imp.py", line 343, 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 "demo/run_dqn_on_pong.py", line 20, in
import tensorflow as tf
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_init_.py", line 101, in
from tensorflow_core import *
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_core_init_.py", line 40, in
from tensorflow.python.tools import module_util as module_util
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_init
.py", line 50, in getattr
module = self.load()
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_init
.py", line 44, in _load
module = importlib.import_module(self.name)
File "C:\ProgramData\Anaconda3\envs\3\lib\importlib_init
.py", line 126, in import_module
return _bootstrap.gcd_import(name[level:], package, level)
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python_init
.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Travis\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Travis\AppData\Roaming\Python\Python36\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:\ProgramData\Anaconda3\envs\3\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\ProgramData\Anaconda3\envs\3\lib\imp.py", line 343, 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.

I have no idea what I can do with the error message...
Win 10, Python 3.6

@jcblucero
Copy link

jcblucero commented Mar 21, 2020

I upgraded to free version of Microsoft Visual Studio Community 2019 Version 16.4.5 including Microsoft Visual C++ 2019 then reinstalled TensorFlow 2.1.0 and it worked without issues. I really needed Tensorflow 2.1.0 for an application I wanted to test.
Rick

Installing Microsoft Visual Studio 2019 community version worked for me on too. Thanks! I am using Tensorflow 2.1.0 + CUDA 10.1

@HebaGamalElDin
Copy link

HebaGamalElDin commented Mar 26, 2020

HI,
Please For my Case::
windows 10 , CPU only , python 3.7 .
i have read all the issue and the another issue was puplished with this one off TF site, i have tried many things but having same error.
i have installed Microsoft Visual C++ 2019 too.
What Else, any help?

===========
I'm also tried to dowwngrade the eversion from 2.1.0 to 2.0.0 but got this error

ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\users\hebagamaleldin\anaconda3-1\lib\site-packages\~ensorflow_core\python\_pywrap_tensorflow_internal.pyd'
Consider using the --user option or check the permissions.

@armiro
Copy link

armiro commented Mar 29, 2020

HI,
Please For my Case::
windows 10 , CPU only , python 3.7 .
i have read all the issue and the another issue was puplished with this one off TF site, i have tried many things but having same error.
i have installed Microsoft Visual C++ 2019 too.
What Else, any help?

===========
I'm also tried to dowwngrade the eversion from 2.1.0 to 2.0.0 but got this error

ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\users\hebagamaleldin\anaconda3-1\lib\site-packages~ensorflow_core\python_pywrap_tensorflow_internal.pyd'
Consider using the --user option or check the permissions.

Simply running the command-prompt/anaconda-prompt as administrator should solve the problem of the downgrade permission.

@gayathri-kannanv
Copy link

gayathri-kannanv commented Apr 1, 2020

I have tried all the above methods. But still getting this error.

I have a doubt. Actually what are the things to be installed to get tensorflow work?
Is not we install tensorflow with pip enough? But that shows this error.

I even have visual c++ redistributable 2005. And tried changing different versions of tensorflow.

Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow
Traceback (most recent call last):
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "F:\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 "F:\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "F:\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "F:\lib\site-packages\tensorflow_init_.py", line 99, in
from tensorflow_core import *
File "F:\lib\site-packages\tensorflow_core_init_.py", line 28, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "F:\lib\site-packages\tensorflow_init_.py", line 50, in getattr
module = self.load()
File "F:\lib\site-packages\tensorflow_init
.py", line 44, in _load
module = importlib.import_module(self.name)
File "F:\lib\importlib_init
.py", line 127, in import_module
return _bootstrap.gcd_import(name[level:], package, level)
File "F:\lib\site-packages\tensorflow_core\python_init
.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "F:\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 "F:\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "F:\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

Failed to load the native TensorFlow runtime.

@ritu13malik
Copy link

After successfully installed tensorflow. I get the same error again n again...........

C:\Users\ritu\AppData\Local\Programs\Python\Python37\Scripts>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow
Traceback (most recent call last):
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_init_.py", line 27, in
from tensorflow.api.v2 import audio
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_api\v2\audio_init
.py", line 8, in
from tensorflow.python.ops.gen_audio_ops import decode_wav
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python_init_.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\ritu\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

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.

@HebaGamalElDin
Copy link

HebaGamalElDin commented Apr 9, 2020

I have tried all the above methods. But still getting this error.

I have a doubt. Actually what are the things to be installed to get tensorflow work?
Is not we install tensorflow with pip enough? But that shows this error.

I even have visual c++ redistributable 2005. And tried changing different versions of tensorflow.

Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow
Traceback (most recent call last):
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "F:\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 "F:\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "F:\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "F:\lib\site-packages\tensorflow__init__.py", line 99, in
from tensorflow_core import *
File "F:\lib\site-packages\tensorflow_core__init__.py", line 28, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "F:\lib\site-packages\tensorflow__init__.py", line 50, in getattr
module = self.load()
File "F:\lib\site-packages\tensorflow__init
_.py", line 44, in load
module = importlib.import_module(self.name)
File "F:\lib\importlib__init
.py", line 127, in import_module
return bootstrap.gcd_import(name[level:], package, level)
File "F:\lib\site-packages\tensorflow_core\python__init
.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "F:\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "F:\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 "F:\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "F:\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

Failed to load the native TensorFlow runtime.

Look if you try to install version 2.0.0 so you must Update pip first then install tensorflow or tensorflow-gpu will work.
If you have the same problem you probably have a CPU issue with the new version (if your laptop isn't core i3 or i5 or i7, i mean your processor is celeron or something earlier than core i3) in thia case try to install version 1.15 and it will work correctly .
If you try to install version 2.0.1 so you must install visual C++ 2015-2019

Resource :: https://www.tensorflow.org/install/pip?lang=python3

@abhmalik
Copy link

This fixed it for me:
Windows 7 or later (64-bit) (Python 3 only)
Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019

@bbetulkaya
Copy link

Had this issue with Tensorflow 2.1.0 (CPU version). Managed to fix it by downgrading to Tensorflow 2.0.0:

pip install tensorflow==2.0.0

thank you so muuuuch

@ryancbolton
Copy link

This also worked for me after downgrading from 2.1.0.

@gsteri1
Copy link

gsteri1 commented May 3, 2020

Check that all the dependencies are installed. I was missing VC redist.

@pike-msonda
Copy link

pike-msonda commented May 7, 2020

This fixed it for me:
Windows 7 or later (64-bit) (Python 3 only)
Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019

This worked also for me on 2.1.0
Python 3.6.5

@ryanDev28
Copy link

Hi. Semi-experiencde programmer, new to Python, novice Linux user taking a course on tensorflow, but stuck. For context, I'm using Jupyter notebooks because that is the tool the online training videos are using, and easy to follow along in real time. This is my first post to github too. This thread has been helpful, as I've seen similar errors, but downgrading to 2.0.0 created other issues. Please read on.

SETUP:
Windows 10 Pro 10.0.18363
Dell Optiplex 5060
Intel i7 8700 (x64)
Anaconda 1.9.12 (Navigator)
Python 3.7.6 (installed with Anaconda)
Running python through Jupyter Notebooks (installed with Anaconda)
installed tensorflow using Anaconda powershell prompt (pip install tensorflow) v2.2.0 installed
Running through Anaconda "base" environment

ISSUE
When I run the single line, "import tensorflow as tf", in a Jupyter notebook, I get the following error message below... which sounds very familiar to other issues people have had above.


ImportError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in
57
---> 58 from tensorflow.python.pywrap_tensorflow_internal import *
59
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in
27 return _mod
---> 28 _pywrap_tensorflow_internal = swig_import_helper()
29 del swig_import_helper
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
23 try:
---> 24 _mod = imp.load_module('pywrap_tensorflow_internal', fp, pathname, description)
25 finally:
C:\ProgramData\Anaconda3\lib\imp.py in load_module(name, file, filename, details)
241 else:
--> 242 return load_dynamic(name, filename, file)
243 elif type
== PKG_DIRECTORY:

C:\ProgramData\Anaconda3\lib\imp.py in load_dynamic(name, path, file)
341 name=name, loader=loader, origin=path)
--> 342 return load(spec)
343
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
in
----> 1 import tensorflow as tf
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_init
.py in
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

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python_init_.py in
48 import numpy as np
49
---> 50 from tensorflow.python import pywrap_tensorflow
51
52 # Protocol buffers

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in
67 for some common reasons and solutions. Include the entire stack trace
68 above this error message when asking for help.""" % traceback.format_exc()
---> 69 raise ImportError(msg)
70
71 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

ImportError: Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\ProgramData\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\ProgramData\Anaconda3\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.


I tried downgrading to tensorflow 2.0.0 using "pip install tensorflow==2.0.0" from the Anaconda powershell window. Going back to the same Jupyter notebook, "import tensorflow as tf" executed without any errors. Great. But then I continued on in the training and found the tensorflow constant and variable methods threw errors. Code and errors below

CODE - Constant

const_1 = tf.constant(value=[5.0],
dtype=tf.float32,
shape=(1,),
name="const_1",
verify_shape=False)
print(const_1)

ERROR

TypeError Traceback (most recent call last)
in
3 shape=(1,),
4 name="const_1",
----> 5 verify_shape=False)
6 print(const_1)

TypeError: constant() got an unexpected keyword argument 'verify_shape'


CODE - variable

var_1 = tf.Variable(initial_value=[1.0],
trainable=True,
collections=None,
validate_shape=True,
caching_device=None,
name='var_1',
variable_def=None,
dtype=tf.float32,
expected_shape=(1,),
import_scope=None)
print(var_1)

ERROR 1

TypeError Traceback (most recent call last)
in
8 dtype=tf.float32,
9 expected_shape=(1,),
---> 10 import_scope=None)
11 print(var_1)

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\ops\variables.py in call(cls, *args, **kwargs)
258 return cls._variable_v1_call(*args, **kwargs)
259 elif cls is Variable:
--> 260 return cls._variable_v2_call(*args, **kwargs)
261 else:
262 return super(VariableMetaclass, cls).call(*args, **kwargs)

TypeError: _variable_v2_call() got an unexpected keyword argument 'collections'


ERROR 2 (after removing collections argument)

TypeError Traceback (most recent call last)
in
8 dtype=tf.float32,
9 expected_shape=(1,),
---> 10 import_scope=None)
11 print(var_1)

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\ops\variables.py in call(cls, *args, **kwargs)
258 return cls._variable_v1_call(*args, **kwargs)
259 elif cls is Variable:
--> 260 return cls._variable_v2_call(*args, **kwargs)
261 else:
262 return super(VariableMetaclass, cls).call(*args, **kwargs)

TypeError: _variable_v2_call() got an unexpected keyword argument 'expected_shape'


And if I remove the verify_shape argument from constant and collections and expected_shape from variable, they execute fine, but I fear I will run into other issues eventually. Rather than continuing this guessing game, I thought I'd check here to see if anyone has any thoughts. Any help is GREATLY appreciated. I ran "pip list" and pasted below in case there any version issues. Thanks in advance!


Package Version

absl-py 0.9.0
alabaster 0.7.12
anaconda-client 1.7.2
anaconda-navigator 1.9.12
anaconda-project 0.8.3
argh 0.26.2
asn1crypto 1.3.0
astor 0.8.1
astroid 2.3.3
astropy 4.0
astunparse 1.6.3
atomicwrites 1.3.0
attrs 19.3.0
autopep8 1.4.4
Babel 2.8.0
backcall 0.1.0
backports.functools-lru-cache 1.6.1
backports.shutil-get-terminal-size 1.0.0
backports.tempfile 1.0
backports.weakref 1.0.post1
bcrypt 3.1.7
beautifulsoup4 4.8.2
bitarray 1.2.1
bkcharts 0.2
bleach 3.1.0
bokeh 1.4.0
boto 2.49.0
Bottleneck 1.3.2
cachetools 4.1.0
certifi 2019.11.28
cffi 1.14.0
chardet 3.0.4
Click 7.0
cloudpickle 1.3.0
clyent 1.2.2
colorama 0.4.3
comtypes 1.1.7
conda 4.8.2
conda-build 3.18.11
conda-package-handling 1.6.0
conda-verify 3.4.2
contextlib2 0.6.0.post1
cryptography 2.8
cycler 0.10.0
Cython 0.29.15
cytoolz 0.10.1
dask 2.11.0
decorator 4.4.1
defusedxml 0.6.0
diff-match-patch 20181111
distributed 2.11.0
docutils 0.16
entrypoints 0.3
et-xmlfile 1.0.1
fastcache 1.1.0
filelock 3.0.12
flake8 3.7.9
Flask 1.1.1
fsspec 0.6.2
future 0.18.2
gast 0.2.2
gevent 1.4.0
glob2 0.7
google-auth 1.14.2
google-auth-oauthlib 0.4.1
google-pasta 0.2.0
greenlet 0.4.15
grpcio 1.28.1
h5py 2.10.0
HeapDict 1.0.1
html5lib 1.0.1
hypothesis 5.5.4
idna 2.8
imageio 2.6.1
imagesize 1.2.0
importlib-metadata 1.5.0
intervaltree 3.0.2
ipykernel 5.1.4
ipython 7.12.0
ipython-genutils 0.2.0
ipywidgets 7.5.1
isort 4.3.21
itsdangerous 1.1.0
jdcal 1.4.1
jedi 0.14.1
Jinja2 2.11.1
joblib 0.14.1
json5 0.9.1
jsonschema 3.2.0
jupyter 1.0.0
jupyter-client 5.3.4
jupyter-console 6.1.0
jupyter-core 4.6.1
jupyterlab 1.2.6
jupyterlab-server 1.0.6
Keras-Applications 1.0.8
Keras-Preprocessing 1.1.0
keyring 21.1.0
kiwisolver 1.1.0
lazy-object-proxy 1.4.3
libarchive-c 2.8
llvmlite 0.31.0
locket 0.2.0
lxml 4.5.0
Markdown 3.2.1
MarkupSafe 1.1.1
matplotlib 3.1.3
mccabe 0.6.1
menuinst 1.4.16
mistune 0.8.4
mkl-fft 1.0.15
mkl-random 1.1.0
mkl-service 2.3.0
mock 4.0.1
more-itertools 8.2.0
mpmath 1.1.0
msgpack 0.6.1
multipledispatch 0.6.0
navigator-updater 0.2.1
nbconvert 5.6.1
nbformat 5.0.4
networkx 2.4
nltk 3.4.5
nose 1.3.7
notebook 6.0.3
numba 0.48.0
numexpr 2.7.1
numpy 1.18.1
numpydoc 0.9.2
oauthlib 3.1.0
olefile 0.46
openpyxl 3.0.3
opt-einsum 3.2.1
packaging 20.1
pandas 1.0.1
pandocfilters 1.4.2
paramiko 2.7.1
parso 0.5.2
partd 1.1.0
path 13.1.0
pathlib2 2.3.5
pathtools 0.1.2
patsy 0.5.1
pep8 1.7.1
pexpect 4.8.0
pickleshare 0.7.5
Pillow 7.0.0
pip 20.0.2
pkginfo 1.5.0.1
pluggy 0.13.1
ply 3.11
prometheus-client 0.7.1
prompt-toolkit 3.0.3
protobuf 3.11.3
psutil 5.6.7
py 1.8.1
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycodestyle 2.5.0
pycosat 0.6.3
pycparser 2.19
pycrypto 2.6.1
pycurl 7.43.0.5
pydocstyle 4.0.1
pyflakes 2.1.1
Pygments 2.5.2
pylint 2.4.4
PyNaCl 1.3.0
pyodbc 4.0.0-unsupported
pyOpenSSL 19.1.0
pyparsing 2.4.6
pyreadline 2.1
pyrsistent 0.15.7
PySocks 1.7.1
pytest 5.3.5
pytest-arraydiff 0.3
pytest-astropy 0.8.0
pytest-astropy-header 0.1.2
pytest-doctestplus 0.5.0
pytest-openfiles 0.4.0
pytest-remotedata 0.3.2
python-dateutil 2.8.1
python-jsonrpc-server 0.3.4
python-language-server 0.31.7
pytz 2019.3
PyWavelets 1.1.1
pywin32 227
pywin32-ctypes 0.2.0
pywinpty 0.5.7
PyYAML 5.3
pyzmq 18.1.1
QDarkStyle 2.8
QtAwesome 0.6.1
qtconsole 4.6.0
QtPy 1.9.0
requests 2.22.0
requests-oauthlib 1.3.0
rope 0.16.0
rsa 4.0
Rtree 0.9.3
ruamel-yaml 0.15.87
scikit-image 0.16.2
scikit-learn 0.22.1
scipy 1.4.1
seaborn 0.10.0
Send2Trash 1.5.0
setuptools 45.2.0.post20200210
simplegeneric 0.8.1
singledispatch 3.4.0.3
six 1.14.0
snowballstemmer 2.0.0
sortedcollections 1.1.2
sortedcontainers 2.1.0
soupsieve 1.9.5
Sphinx 2.4.0
sphinxcontrib-applehelp 1.0.1
sphinxcontrib-devhelp 1.0.1
sphinxcontrib-htmlhelp 1.0.2
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 1.0.2
sphinxcontrib-serializinghtml 1.1.3
sphinxcontrib-websupport 1.2.0
spyder 4.0.1
spyder-kernels 1.8.1
SQLAlchemy 1.3.13
statsmodels 0.11.0
sympy 1.5.1
tables 3.6.1
tblib 1.6.0
tensorboard 2.0.2
tensorboard-plugin-wit 1.6.0.post3
tensorflow 2.0.0
tensorflow-estimator 2.0.1
termcolor 1.1.0
terminado 0.8.3
testpath 0.4.4
toolz 0.10.0
tornado 6.0.3
tqdm 4.42.1
traitlets 4.3.3
ujson 1.35
unicodecsv 0.14.1
urllib3 1.25.8
watchdog 0.10.2
wcwidth 0.1.8
webencodings 0.5.1
Werkzeug 1.0.0
wheel 0.34.2
widgetsnbextension 3.5.1
win-inet-pton 1.1.0
win-unicode-console 0.5
wincertstore 0.2
wrapt 1.11.2
xlrd 1.2.0
XlsxWriter 1.2.7
xlwings 0.17.1
xlwt 1.3.0
xmltodict 0.12.0
yapf 0.28.0
zict 1.0.0
zipp 2.2.0

@JUNETYCOON
Copy link

I see an article and I ,finally solve this problem.Win10,anaconda3,tensorflow2.2.0.

enter cmd
pip uninstall pillow
conda update pip
pip install pillow

that's all.I hope it will help you

@mareksojka
Copy link

pip install tensorflow==2.0.0
solved my problem

@fidelm-22
Copy link

how can I solve this problem

ImportError: Traceback (most recent call last):
File "C:\Users\HP\anaconda7\envs\PY3-TF2.0\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\HP\anaconda7\envs\PY3-TF2.0\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\HP\anaconda7\envs\PY3-TF2.0\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\HP\anaconda7\envs\PY3-TF2.0\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\HP\anaconda7\envs\PY3-TF2.0\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.

@rabi24
Copy link

rabi24 commented Dec 12, 2020

import keras
Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 343, 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 "", line 1, in
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras__init__.py", line 3, in
from . import utils
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils__init__.py", line 6, in
from . import conv_utils
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\conv_utils.py", line 9, in
from .. import backend as K
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend__init__.py", line 89, in
from .tensorflow_backend import *
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in
import tensorflow as tf
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow__init__.py", line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python__init__.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Rajesh Kumar Khatik\AppData\Local\Programs\Python\Python36\Lib\imp.py", line 343, 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.

Please help me with this error

same error
Im using windows 10
python 3.7.8

@SushP07
Copy link

SushP07 commented Jan 24, 2021

import tensorflow
Traceback (most recent call last):
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
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:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\tensorflow_init_.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\tensorflow\python_init
.py", line 39, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
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.

@SushP07
Copy link

SushP07 commented Jan 24, 2021

I am having this error. How to solve this?

@MarkusRabe
Copy link

Same problem here. Somewhere hidden in the long thread above there is the hint to go back to tensorflow 2.0.0:
pip install tensorflow=2.0.0

That solved it for me.

@vickcn
Copy link

vickcn commented Mar 9, 2021

I am having that problem, too! Expect solutions, thanks!

ImportError: Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: 找不到指定的模組。

@BaliDataMan
Copy link

BaliDataMan commented Mar 2, 2022

Same problem here. Somewhere hidden in the long thread above there is the hint to go back to tensorflow 2.0.0: pip install tensorflow=2.0.0

That solved it for me.

Correction: pip install tensorflow==2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests