Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复-ImportError:导入keras时DLL加载失败_Python_Windows_Tensorflow_Keras - Fatal编程技术网

Python 如何修复-ImportError:导入keras时DLL加载失败

Python 如何修复-ImportError:导入keras时DLL加载失败,python,windows,tensorflow,keras,Python,Windows,Tensorflow,Keras,我正在尝试使用tensorflow后端安装keras 我首先运行了pip-install-keras,然后运行了pip-install-tensorflow 这两个命令都成功地完成了,现在当我尝试从keras.models导入Sequential时,出现了错误 这是我的密码 这是一个错误 Using TensorFlow backend. Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Progra

我正在尝试使用tensorflow后端安装keras

我首先运行了
pip-install-keras
,然后运行了
pip-install-tensorflow
这两个命令都成功地完成了,现在当我尝试从keras.models导入Sequential时,出现了错误

这是我的密码

这是一个错误

Using TensorFlow backend.
Traceback (most recent call last):
  File "C:\Users\Admin\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\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Admin\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\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: Произошел сбой в программе инициализации библиотеки динамической компоновки (DLL).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Admin/PycharmProjects/keras/test.py", line 3, in <module>
    from keras.models import Sequential
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "C:\Users\Admin\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\Admin\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\Admin\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\Admin\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\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Admin\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\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: Произошел сбой в программе инициализации библиотеки динамической компоновки (DLL).


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.
我正在使用

和Python 3.6.0


有人能帮我解决这个问题吗?

方法1

因此,根据您提供的信息,请遵循以下步骤:

  • 安装
  • 由于您的CPU不支持AVX,请转到此处。它包含支持SSE的TensorFlow版本,SSE与英特尔奔腾兼容
  • 在回购协议中遵循此路径->
  • 下载.whl文件(或单击)
  • 现在,我们需要安装这个文件。使用

    pip安装tensorflow-1.12.0-cp36-cp36m-win_amd64.whl

  • 如果显示任何错误,请尝试将相对路径更改为绝对路径

  • TensorFlow已成功安装

  • 方法2

    安装。它使用名为
    conda
    的包管理器,类似于
    pip

  • 创建一个新的Conda环境

    conda create——名称mytfenv

  • 安装TensorFlow(版本=1.10.0)

    conda安装tensorflow


  • 其中一种方法对你有用。我个人遵循了这两种方法,因为我的CPU规格与您的一致。

    Tensorflow 1.12与Keras一起推出(
    tf.Keras
    :)。因此,您必须首先导入tensorflow和keras,然后使用
    keras.Sequential
    创建图层

    import tensorflow as tf
    from tensorflow import keras
    
    #for example
    model = keras.Sequential([
        keras.layers.Flatten(input_shape=(28, 28)),
        keras.layers.Dense(128, activation=tf.nn.relu),
        keras.layers.Dense(10, activation=tf.nn.softmax)
    ])
    

    有关更多信息,请参阅官方教程:

    对于CPU,只需在jupyter笔记本中运行以下python代码即可安装tensorflow。我希望你安装了水蟒


    大于1.6版的tensorflow可能会给您带来问题,但它附带了一些有用的功能

    我对Windows 10上的Python 3.7、Jypyter Notebook也有同样的问题。这样做:

  • 安装-Visual Studio 2015、2017和2019。重新启动
  • 并在我的Jypyter笔记本中安装指南:

    • pip安装--升级pip

    • pip安装tensorflow

  • 然后我的命令
    import tensorflow
    import keras
    正常工作

  • 您可以安装Anaconda,创建虚拟环境,在其上安装Keras和Tensorflow,如果jupyter笔记本中仍然出现DLL导入错误-
    打开链接,下载x64.exe文件并安装它

    您的CPU支持AVX指令吗?看。此外,请注意您是否安装了VisualStudioC++ +可重新分发的2015更新3。我的处理器是“代码>英特尔(R)奔腾(R)CPU B980 < /代码>,并且我理解了代码> Pentium < /Calp>处理器不支持<代码> AVX。不,我没有安装<代码> VisualStudioC++ +可重新分发< /COD>为什么我不能用PIP安装1.10版?因为从1.6.0开始TensorFlow官方pip包只支持AVX。
    import tensorflow as tf
    from tensorflow import keras
    
    #for example
    model = keras.Sequential([
        keras.layers.Flatten(input_shape=(28, 28)),
        keras.layers.Dense(128, activation=tf.nn.relu),
        keras.layers.Dense(10, activation=tf.nn.softmax)
    ])
    
              pip.main(['install','tensorflow==1.5'])