Issue installing Tensorflow — not a CUDA/CuDNN iss

2019-01-01 01:24发布

I recently started getting into Tensorflow, but i'm having issues with the install. Everytime I try to import it I get the following error

>>> import tensorflow as tf
Traceback (most recent call last):
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\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\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\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\[user]\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: 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\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\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\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\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\[user]\AppData\Local\Programs\Python\Python36\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.

I looked at other stack overflow posts that were having the same problem as me, and they suggested getting the CUDA libraries from NVIDIA. The problem is, I have neither a NVIDIA graphics card nor the GPU version of tensorflow, so I don't think that's the issue. There were also suggestions to make sure the Microsoft redistributables for visual studio are installed, which they are.

If this is a system variable based problem, I'd appreciate help with changing system variables as I'm new to doing that. Thank you!

Some System Info:

  • OS: Microsoft Windows 10 Pro Version 10.0.17134
  • CPU: Intel Xeon E5620
  • Graphics Card: Radeon RX 480
  • Python Version: 3.6.5 amd64 Tensorflow
  • Install method: pip install tensorflow

4条回答
初与友歌
2楼-- · 2019-01-01 01:44

My guess is that you are trying to use TF >= 1.6, because your CPU is rather old and does not support AVX instructions. Indeed from 1.6 on, tensorflow pre-built binaries use AVX instructions.

Currently your options are either to:

  1. Use an official pre-built binary of TF 1.5 or earlier. (You will miss a few things but it's still OK I would say).
  2. Search for an unofficial pre-built binary of TF >= 1.6 that does not support AVX.
    • Currently, pre-built binaries until TF 1.10 from conda install on Windows seem not to be built with AVX support, although I could not find this information anywhere and therefore cannot tell if this is intentional and how long that will be the case.
    • Beware that binaries from conda-forge (which used to be the main conda tensorflow provider before it has been available on the main channel) on the other hand are built with AVX support.
  3. Change your hardware to support AVX (obviously).
  4. Compile your own binary of tensorflow without AVX instructions. A reasonable option if none of the others were possible.
查看更多
高级女魔头
3楼-- · 2019-01-01 01:47

If the problem persists check the version numbering and make sure cuda and TF are compatible.

Check the version numbering here

or for a simpler way, use Anaconda

conda create --name new_env_name tensorflow-gpu
activate new_env_name

I successfully installed TensorFlow GPU version 1.12 (latest until the date of writing) with Cuda 9.0, GeForce 1050 Ti, Windows 10 and Python 3.6.7

Note: You have installed the CUDA Toolkit (version 9) for TensorFlow to recognize your GPU

查看更多
不再属于我。
4楼-- · 2019-01-01 01:51

Have in mind that the above answers are correct for a lot of cases. However, downgrading to tensorflow 1.5 might not be the best solution because for instance, you won't have access to some of the new features of tensorflow like the 'eager execution' feature for example.

What i did in my case was to install tensorflow 1.8 with conda instead of pip. From my little experience with conda and pip, conda seems to perform better when it comes to placing required files in their proper location.

In summary, Instead of pip3 install --upgrade tensorflow, i used conda install tensorflow which will install the latest version properly.

In case you don't have Anaconda installed for conda commands. Download from here

查看更多
步步皆殇っ
5楼-- · 2019-01-01 01:53

@user1735003 figured it out. I unistalled the latest version of tensorflow

pip uninstall tensorflow

and then installed tensorflow 1.5

pip install tensorflow==1.5

then I verified the installation worked with the script

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

I got the correct output

Hello, TensorFlow!
查看更多
登录 后发表回答