21

While trying to validate the installation of tensorflow-gpu, I get an ImportError when trying to execute "import tensorflow as tf". I am using a Quadro K620 on Windows 7. Tensorflow was installed using pip.

The following is the stack trace:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\aagarwal>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_hel
per
    return importlib.import_module(mname)
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\importlib\_
_init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", line 222, 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\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_hel
per
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\importlib\_
_init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_hel
per
    return importlib.import_module(mname)
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\importlib\_
_init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", line 222, 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\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag
es\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_hel
per
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\importlib\_
_init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_probl
ems

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

I have looked at multiple other stack overflow posts which things like correcting the path but I have not been able to solve this issue.

Amit Agarwal
  • 363
  • 1
  • 3
  • 6
  • Possible duplicate of [Cannot import Tensorflow for GPU on Windows 10](https://stackoverflow.com/questions/43577923/cannot-import-tensorflow-for-gpu-on-windows-10) – aldel Aug 18 '17 at 18:59

12 Answers12

7

I came across the same issue today, please switch to cuDNN v5.1 Library for Windows instead as @mickdelaney suggested and then try to

  1. Check environment settings of CUDA, normally all the settings of CUDA had been added to Windows environment

  2. Copy files in bin, lib and include of cuDNN to bin, lib and include of CUDA respectively. Normally the directory is C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA

And then you can import tensorflow and run your code. Good luck!

GoingMyWay
  • 16,802
  • 32
  • 96
  • 149
7

I found the solution for the CPU: It worked for me

Just run below command if necessary then update it

pip install tensorflow==1.5

EKNATH KULKARNI
  • 394
  • 1
  • 5
  • 13
3

you could uninstall the current version of tensorflow and try a low version such as TensorFlow 0.12 using the code

pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl

https://blog.csdn.net/baidu_36669549/article/details/79734590

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
2

After you install the CUDA Drivers you must download cuDNN and release it. After that you get to copy the cudnn64_5.dll to PATH.
If that doesn't work, move the cudnn64_5.dll to NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin and try it again. Otherwise you'd meet some error that you see.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
WHCer
  • 21
  • 1
2

https://github.com/tensorflow/tensorflow/issues/7705

switch to cuDNN 5.1 instead of 6.0

mickdelaney
  • 1,045
  • 1
  • 10
  • 16
2

I had the same error with anaconda, it was previously installed with another program through anaconda. Installing again through conda-forge worked: conda install -c conda-forge tensorflow

cemsazara
  • 1,623
  • 15
  • 14
0

I still got this error after installing cuDNN 5.1 (yes, I had PATH set correctly). I had better luck installing tensorflow_gpu from this site. This requires cuDNN 6.0, not 5.1. Unfortunately they currently only have Tensorflow 1.1 for GPU systems.

aldel
  • 6,489
  • 1
  • 27
  • 32
0

I am a chinese, so my english is poor, and my answer is that however you use cudnn 7 or 6 or 5 , you must rename the dll from cudnn64_x.dll to cudnn64_6.dll after you copy files. maybe soon, you need to rename the dll to 7 or 8 or 9 as possible.

Priyank
  • 1,513
  • 1
  • 18
  • 36
Paul
  • 11
  • 1
0

this is all about your video chip/card and CPU compatibility with TF VERSION! Current version of Tensor Flow is 1.8 and it crashes on both my machines.

I have a win7 Gateway notebook using an I5 CPU and intel video chip. I have a desktop win7 unit with AMD Phenom II and AMD Radeon HD5450 video card. The I5 notebook requires V1.6 of TensorFlow and the desktop AMD unit takes V1.5. I don't have a GPU available for running ANN's so I don't know how that would affect it.

Here's the command line for PIP install: pip install --upgrade tensorflow==1.5.0 (or whatever other version you need). This will uninstall your current version and then install the indicated version.

Build or copy a small TensorFlow script and run it in a command window. Open a second command window and install a different version. I'd recommend starting at 1.5 and working your way up.

0

The only thing that worked for me (Windows 10) is: Install Microsoft Visual C++ 2015 Redistributable Update 3 If you have a new fresh computer setup this one might miss.

maniac
  • 1,112
  • 1
  • 13
  • 19
0

It worked for me after doing this command :

pip install tensorflow-gpu == 1.15.5 

I was previously with tensorflow-gpu 1.15.0 when it was showing the error

0

On macOS,

pip install --upgrade tensorflow==1.5.0

worked for me.

Fkiran
  • 24
  • 3