python - 如何修复 - 导入 keras 时出现 ImportError : DLL load failed,

标签 python windows tensorflow keras

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

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

这是我的代码

code

这里有错误

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.

我不知道为什么错误是俄语,可能是因为我的系统语言,但这里是翻译

Original error:
ImportError: DLL load failed: Произошел сбой в программе инициализации библиотеки динамической компоновки (DLL)

Translation:
ImportError: DLL load failed: A crash occurred in the dynamic link library initialization program. (DLL)

我正在使用

versions

和Python 3.6.0

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

最佳答案

方法 1

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

  1. 安装Visual Studio C++ Redistributable 2015 Update 3 .
  2. 由于您的 CPU 不支持 AVX,请转到此 repository 。它包含支持 SSE 的 TensorFlow 版本,与 Intel Pentium 兼容。
  3. 按照存储库中的此路径 -> tensorflow-windows-wheel/1.12.0/py36/CPU/sse2
  4. 下载 .whl 文件(或点击 here)。
  5. 现在,我们需要安装此文件。使用,

    pip install tensorflow-1.12.0-cp36-cp36m-win_amd64.whl

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

  7. TensorFlow 安装成功。

方法 2

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

  1. 创建新的 Conda 环境。

    conda create --name mytfenv

  2. 安装 TensorFlow(版本=1.10.0)

    conda安装tensorflow

其中一种方法适合您。我个人遵循了这两种方法,因为我的 CPU 规范与您的相符。

关于python - 如何修复 - 导入 keras 时出现 ImportError : DLL load failed,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54609544/

相关文章:

python - evaluate_generator 的准确率为 0%,但在使用相同数据进行训练时准确率为 75%——这是怎么回事?

javascript - AJAX、Django 和 HTML 选择?

python - 对数时间Python中有序列表中的位置元素

windows - Windows 7文件夹资源管理器搜索非常慢

python - 如何输出网络的第二层?

python - ValueError : Shape must be rank 1 but is rank 0 for 'ROIAlign/Crop' (op: 'CropAndResize' ) with input shapes: [2, 360,475,3], [1,4], [], [2]

python - ximgproc_DisparityWLSFilter.filter() 参数是什么?

python - 类型错误 : movement() missing 1 required positional argument: 'self'

Windows下Ruby找不到模块(LoadError)

windows - 在 Delphi 中获取 DLL 调用者信息