进口喀拉拉邦

时间:2018-12-09 05:41:53

标签: python-3.x tensorflow keras

我正在尝试导入keras,代码返回有关tensorflow的错误。

import numpy
import matplotlib.pyplot as plt
import pandas
import math
from keras.models import Sequential
from keras.layers import Dense

错误提示:

Using TensorFlow backend.
Traceback (most recent call last):
  File "C:/Users/gonza/Documents/Projects/jeremiah/neuralNet.py", line 6, in <module>
    from keras.models import Sequential
  File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils
  File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

2 个答案:

答案 0 :(得分:1)

似乎找不到tensorflow。您需要安装tensorflow才能使用keras库。

如果您已经安装了tensorflow,请尝试将其卸载并重新安装。

    sudo pip3 uninstall tensorflow 
    pip3 install --upgrade tensorflow

您可以通过运行以下命令来验证安装:

python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

答案 1 :(得分:0)

此错误与TensorFlow有关。 TensorFlow可能未安装或安装不正确。请检查TensorFlow安装