【问题标题】:Unable to import Keras Library无法导入 Keras 库
【发布时间】:2019-06-05 18:04:15
【问题描述】:

我正在研究数据集上的人工神经网络算法。以下是我正在使用的数据集的来源。

Kaggle Dataset

我已经运行了代码,直到 Feature Scaling 运行成功,没有任何问题。下面是我运行的代码:-

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv("C:\Machine learning\practices\Machine Learning A-Z Template Folder\Part 8 - Deep Learning\Section 39 - Artificial Neural Networks (ANN)\Artificial-Neural-Networks\Artificial_Neural_Networks\Churn1_Modelling.csv")
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

之后我跑了

import keras

当 Python 停止工作并且内核每次都重新启动时,它给了我错误。我已经安装了所有的库和模块。以下是我已经安装的模块:-

Package                            Version
---------------------------------- -----------
alabaster                          0.7.9
anaconda-clean                     1.0
anaconda-client                    1.5.1
anaconda-navigator                 1.3.1
argcomplete                        1.0.0
astroid                            1.4.7
astropy                            1.2.1
Babel                              2.3.4
backports.shutil-get-terminal-size 1.0.0
backports.weakref                  1.0rc1
beautifulsoup4                     4.5.1
bitarray                           0.8.1
blaze                              0.10.1
bleach                             1.5.0
bokeh                              0.12.2
boto                               2.42.0
Bottleneck                         1.1.0
certifi                            2018.8.24
cffi                               1.7.0
chardet                            3.0.4
chest                              0.2.3
click                              6.6
cloudpickle                        0.2.1
clyent                             1.2.2
colorama                           0.3.7
comtypes                           1.1.2
conda                              4.5.11
conda-build                        2.0.2
configobj                          5.0.6
contextlib2                        0.5.3
cryptography                       1.5
cycler                             0.10.0
Cython                             0.24.1
cytoolz                            0.9.0.1
dask                               0.11.0
datashape                          0.5.2
decorator                          4.0.10
dill                               0.2.5
docutils                           0.12
dynd                               c328ab7
et-xmlfile                         1.0.1
fastcache                          1.0.2
filelock                           2.0.6
Flask                              0.11.1
Flask-Cors                         2.1.2
gevent                             1.1.2
greenlet                           0.4.10
h5py                               2.6.0
HeapDict                           1.0.0
html5lib                           0.9999999
idna                               2.1
imagesize                          0.7.1
ipykernel                          4.5.0
ipython                            5.1.0
ipython-genutils                   0.1.0
ipywidgets                         5.2.2
itsdangerous                       0.24
jdcal                              1.2
jedi                               0.9.0
Jinja2                             2.8
jsonschema                         2.5.1
jupyter                            1.0.0
jupyter-client                     4.4.0
jupyter-console                    5.0.0
jupyter-core                       4.2.0
Keras                              2.2.2
Keras-Applications                 1.0.4
Keras-Preprocessing                1.0.2
keyring                            13.2.1
lazy-object-proxy                  1.2.1
llvmlite                           0.13.0
locket                             0.2.0
lxml                               3.6.4
Markdown                           2.2.0
MarkupSafe                         0.23
matplotlib                         1.5.3
menuinst                           1.4.1
mistune                            0.7.3
mkl-fft                            1.0.4
mkl-random                         1.0.1
mpmath                             0.19
multipledispatch                   0.4.8
nb-anacondacloud                   1.2.0
nb-conda                           2.0.0
nb-conda-kernels                   2.0.0
nbconvert                          4.2.0
nbformat                           4.1.0
nbpresent                          3.0.2
networkx                           1.11
nltk                               3.2.1
nose                               1.3.7
notebook                           4.2.3
numba                              0.28.1
numexpr                            2.6.7
numpy                              1.15.1
numpydoc                           0.8.0
odo                                0.5.0
olefile                            0.45.1
openpyxl                           2.3.2
pandas                             0.18.1
partd                              0.3.6
path.py                            0.0.0
pathlib2                           2.1.0
patsy                              0.4.1
pep8                               1.7.0
pickleshare                        0.7.4
Pillow                             5.2.0
pip                                18.0
pkginfo                            1.3.2
ply                                3.9
prompt-toolkit                     1.0.3
protobuf                           3.6.1
psutil                             4.3.1
py                                 1.4.31
pyasn1                             0.1.9
pycodestyle                        2.4.0
pycosat                            0.6.3
pycparser                          2.14
pycrypto                           2.6.1
pycurl                             7.43.0.2
pyflakes                           1.3.0
Pygments                           2.2.0
pylint                             1.5.4
pyOpenSSL                          16.2.0
pyparsing                          2.1.4
pytest                             2.9.2
python-dateutil                    2.5.3
pytz                               2016.6.1
pywin32                            220
PyYAML                             3.12
pyzmq                              15.4.0
QtAwesome                          0.4.4
qtconsole                          4.2.1
QtPy                               1.5.0
requests                           2.14.2
rope-py3k                          0.9.4.post1
ruamel-yaml                        -VERSION
scikit-image                       0.12.3
scikit-learn                       0.19.2
scipy                              1.1.0
setuptools                         40.2.0
simplegeneric                      0.8.1
singledispatch                     3.4.0.3
six                                1.11.0
snowballstemmer                    1.2.1
sockjs-tornado                     1.0.3
sphinx                             1.4.6
spyder                             3.3.1
spyder-kernels                     0.2.4
SQLAlchemy                         1.0.13
statsmodels                        0.6.1
sympy                              1.0
tables                             3.2.2
tensorflow                         1.2.0
Theano                             1.0.2
toolz                              0.8.0
tornado                            4.4.1
traitlets                          4.3.0
unicodecsv                         0.14.1
wcwidth                            0.1.7
Werkzeug                           0.14.1
wheel                              0.31.1
widgetsnbextension                 1.2.6
win-unicode-console                0.5
wincertstore                       0.2
wrapt                              1.10.6
xlrd                               1.0.0
XlsxWriter                         0.9.3
xlwings                            0.10.0
xlwt                               1.1.2

请让我知道安装 tensorflow 和 keras 是否有问题,或者是否有其他问题,因为我无法继续使用人工神经网络算法来预测值。

谢谢。

【问题讨论】:

  • 你得到什么错误信息?
  • 您使用的是哪些包管理器?例如pip, conda, ... 你有多个环境吗?此外,看起来您可能正在使用 Jupyter notebook。您可能会尝试仅在 vanilla python(或 ipython)中运行。
  • 嗨@rocksportrocker,我收到错误,例如python停止工作并且spyder中的内核每次都重新启动。如果我可以在下面的评论中上传相同的屏幕截图,请告诉我?
  • 嗨 @ShpielMeister 我在 python 控制台中使用 pip 并且所有代码都使用 spyder notebook。

标签: python tensorflow machine-learning keras deep-learning


【解决方案1】:

看来您正在学习 SuperDataScience 机器学习 az 课程。
你的代码是正确的,你做得很好。如果您使用的是 anaconda 内核(spyder IDE 使用 anaconda 内核),请尝试通过pip3 install --upgrade tensorflow 安装 tensorflow。
根据您提供的库列表,您已通过 conda forge 安装了 tensorflow。

通过pip 安装 tensorflow 后,尝试通过

测试您的 tensorflow 安装 将张量流导入为 tf 你好 = tf.constant('你好,TensorFlow!') sess = tf.Session() 打印(sess.run(你好))

你应该看到这个输出Hello, TensorFlow!
现在您可以通过运行此代码pip install keras
import keras 来尝试检查您的keras 安装。你应该看到这个输出:Using TensorFlow backend.

最好的问候

【讨论】:

  • 有时pip3 在系统命令行界面中无法正常工作,因此请尝试在 jupyter notebook 中使用此代码:!pip3 install --upgrade tensorflow 和 keras !pip install keras。并尝试运行提到的代码。
猜你喜欢
  • 2018-07-14
  • 2020-06-10
  • 2019-02-09
  • 2018-07-20
  • 2023-04-11
  • 2019-02-12
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
相关资源
最近更新 更多