【问题标题】:Error in importing Sequential from Keras.Models从 Keras.Models 导入 Sequential 时出错
【发布时间】:2021-11-03 05:40:21
【问题描述】:

我已经使用pip install keras 安装了 Keras,并通过python -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py2-none-any.whl 安装了 tensorflow 版本 1.9.0。我按照post 的指示,选择了一个似乎可以安装在我的电脑上的版本。我不确定是不是因为版本太旧了。我在 Windows 计算机上使用 Python 2。我正在运行以下导入语句并收到以下错误消息。

from keras.models import Sequential
from keras.layers import Dense

错误:

Traceback (most recent call last):
  File "C:\Downloads\keras_code.py", line 2, in <module>
    from keras.models import Sequential
  File "C:\Python27\lib\site-packages\keras\__init__.py", line 21, in <module>
    from tensorflow.python import tf2
  File "C:\Python27\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Python27\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Python27\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Python27\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Python27\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ImportError: No module named _pywrap_tensorflow_internal


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.

不可能立即获得一台新计算机,有没有办法让 keras/tensorflow 在旧计算机上工作?

【问题讨论】:

标签: python windows tensorflow keras python-2.x


【解决方案1】:

@Jellyfish,您使用的是非常旧的 Tensorflow 版本。安装最新的 TensorFlow 版本 2.6.0。最新的 TensorFlow 版本也安装了 Keras 库。

使用如下导入。

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

【讨论】:

    猜你喜欢
    • 2020-04-10
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多