【问题标题】:ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failedImportError:DLL 加载失败:动态链接库 (DLL) 初始化例程失败
【发布时间】:2018-04-20 02:29:17
【问题描述】:

我在 Conda 环境中使用 CUDA Toolkit v9.0 和 cuDNNv7.1 和 Python 3.6 安装了具有 CPU 支持的 TensorFlow。

我按照 TensorFlow 网站中描述的说明进行操作,当我尝试时:

import tensorflow as tf

我收到了这个错误:

Traceback (most recent call last):
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
        from tensorflow.python.pywrap_tensorflow_internal import *
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>
        _pywrap_tensorflow_internal = swig_import_helper()
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
        return importlib.import_module(mname)
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\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.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
        from tensorflow.python import *  # pylint: disable=redefined-builtin
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
        from tensorflow.python import pywrap_tensorflow
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
        raise ImportError(msg)
    ImportError: Traceback (most recent call last):
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
        from tensorflow.python.pywrap_tensorflow_internal import *
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>
        _pywrap_tensorflow_internal = swig_import_helper()
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
        return importlib.import_module(mname)
      File "C:\Users\31121\AppData\Local\conda\conda\envs\tensorflow_gpu\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.

我错过了什么吗?

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    我找到了解决方案,可能是你的 cpu 不支持 AVX,所以我从 github 上的这个定制存储库安装 tensorflow 链接在这里

    https://github.com/fo40225/tensorflow-windows-wheel

    我在该文件夹中为 py 37 选择了 1.12.0 选择 py36 文件夹和 cpu 文件夹并在 sse2 中下载文件

    不支持下载sse2 whl的cpu

    【讨论】:

    • 请不要只提供链接作为答案。使用它们来备份您的解决方案,而不是作为实际解决方案。
    【解决方案2】:

    使用 pip 而不是 conda 时会出现问题

    最好的答案是(100% 有效):

    键入以下命令: 如果已经安装了 TensorFlow,你应该通过以下命令重新安装它:

     pip uninstall TensorFlow
    

    如果没有,请通过以下命令安装:

     conda install TensorFlow
    

    我从下面的这个链接得到这个解决方案:

    https://github.com/tensorflow/tensorflow/issues/23683#issuecomment-513788003

    感谢 @sdmars Tamiris Crepalde,她正在帮助我找到解决方案:

    enter image description here

    【讨论】:

    • 谢谢,这似乎是从 pip install 安装 1.14 版而不是 2+ 版
    【解决方案3】:

    这是一个简单的解决方案(没有 conda,没有 gpu/cpu 人员)

    卸载您已安装的任何 tensorflow 版本。

    pip uninstall tensorflow
    

    安装张量流 1.15

    pip install tensorflow==1.15
    

    运行python

    那就试试import tensorflow

    【讨论】:

    • 它说“找不到满足要求的版本”并提供从 1.13.1 到 2.3.0rc0 的系列。
    【解决方案4】:

    我遇到了类似的问题。我知道我的 CPU (Pentium G4560) 不支持 AVX,所以我将 tensorflow 版本从 1.6 更改为 1.5。手册有链接:

    https://github.com/rohit-patel/Install_Instructions-Win10-Deeplearning-Keras-Tensorflow

    【讨论】:

      【解决方案5】:

      我遇到了类似的问题。我有一台装有 Intel Celeron J3455 的计算机,我发现我的 CPU 不支持 AVX,所以我不能使用 TensorFlow 1.6 中包含的官方二进制文件。

      正如ABHAY KOTAL 建议的那样,你可以使用一个非官方的轮子,你可以在以下存储库中找到它:https://github.com/fo40225/tensorflow-windows-wheel

      就我而言,我为 Python 3.7 (py37) 选择了 Tensorflow 1.15:tensorflow-1.15.0-cp37-cp37m-win_amd64.whl。如果您想要其他版本,请下载可用的sse2 版本。

      要安装新的 TensorFlow:

      pip install tensorflow-1.15.0-cp37-cp37m-win_amd64.whl
      

      记得在安装之前的 TensorFlow 版本之前卸载:

      pip uninstall tensorflow tensorboard tensorboard-plugin-wit tensorflow-estimator tensorflow-tensorboard
      

      【讨论】:

        【解决方案6】:

        在另一个线程上找到了这个解决方案:https://github.com/tensorflow/tensorflow/issues/23683

        各位,我已经通过另一条路解决了我的问题。我卸载了我使用 pip 安装的 TensorFlow 包,然后使用“conda install TensorFlow”重新安装,它成功了!现在我可以毫无问题地导入 TensorFlow。希望对大家也有帮助!

        【讨论】:

          【解决方案7】:

          我遇到了同样的问题。我意识到我的 CPU 不支持 AVX。我将 tensorflow 降级到 1.5,它就像一个魅力

          pip install tensorflow==1.5
          

          如果没有,您也可以尝试从源代码安装 tensorflow here 以防你的 CPU 也不支持 AVX。

          【讨论】:

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