【问题标题】:Error while importing Tensorflow. A dynamic link library (DLL) initialization routine failed导入 TensorFlow 时出错。动态链接库 (DLL) 初始化例程失败
【发布时间】:2018-04-23 07:32:53
【问题描述】:

我使用 tensorflow CPU 有一段时间了,并决定安装 tf gpu,现在当我尝试导入 tf 时,它给了我这个错误。 我的系统规格是: 英特尔至强 w5320 2.8 Ghz 8 线程。 10 GB 内存 英伟达 GTX 1050 2GB 我已经为 CUDA 9.0 安装了最新的驱动程序,Cuda 9.0 和 cuDNN v7.1.3(2018 年 4 月 17 日)。 任何形式的帮助表示赞赏。

ImportError                               Traceback (most recent call last)
C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>()
     57 
---> 58   from tensorflow.python.pywrap_tensorflow_internal import *
     59   from tensorflow.python.pywrap_tensorflow_internal import __version__

C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in <module>()
     17         return importlib.import_module(mname)
---> 18     _pywrap_tensorflow_internal = swig_import_helper()
     19     del swig_import_helper

C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
     16         mname = '.'.join((pkg, '_pywrap_tensorflow_internal')).lstrip('.')
---> 17         return importlib.import_module(mname)
     18     _pywrap_tensorflow_internal = swig_import_helper()

C:\Users\Arsalan\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-5-fe877e2db533> in <module>()
----> 1 import tensorflow as tf
      2 import numpy as np
      3 import matplotlib.pyplot as plt

C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>()
     22 
     23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *  # pylint: disable=redefined-builtin
     25 # pylint: enable=wildcard-import
     26 

C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>()
     47 import numpy as np
     48 
---> 49 from tensorflow.python import pywrap_tensorflow
     50 
     51 # Protocol buffers

C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>()
     72 for some common reasons and solutions.  Include the entire stack trace
     73 above this error message when asking for help.""" % traceback.format_exc()
---> 74   raise ImportError(msg)
     75 
     76 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

ImportError: Traceback (most recent call last):
  File "C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Arsalan\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\Arsalan\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
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.

【问题讨论】:

    标签: python python-3.x tensorflow


    【解决方案1】:

    以下脚本帮助我查明了我在 Windows 上安装 Tensorflow GPU 时出现的问题:https://gist.github.com/diarabit/17d9051f9505c9d554d8a7d0c2bc4eb1
    我希望这对你也有帮助。

    最好的问候。

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。可能会删除仅是链接的答案。见stackoverflow.com/help/deleted-answers
    • @Spangen 我明白了,我将尝试解释脚本的实际作用,以便未来的用户可以手动执行相同的操作。明天我会努力做到的。
    • 所有必需的 DLL 似乎都存在。请在 TensorFlow GitHub 页面上打开一个问题:github.com/tensorflow/tensorflow/issues 发生异常,使用 %tb 查看完整的回溯。
    • 此脚本主要用于 GPU 版本的 TF。对于 CPU 版本,它没有多大帮助。
    【解决方案2】:

    https://github.com/rohit-patel/Install_Instructions-Win10-Deeplearning-Keras-Tensorflow 我准确地关注了这篇文章并让它工作。 实际问题是我没有带 AVX 的 CPU,我需要安装兼容 CUDA 和 cudNN 的 tensorflow 1.5。 我希望它能解决每个人的问题。 谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 2017-04-21
      • 2018-02-03
      • 1970-01-01
      相关资源
      最近更新 更多