Google Cloud DataLab中找不到该模块

时间:2017-11-25 16:54:24

标签: google-cloud-datalab

我正在使用Google Cloud DataLab,这是在Google的云计算引擎上运行的ipython笔记本,我试图安装python模块keras,但笔记本声称它无法找到它。我正在运行Python3(并在安装后重新启动内核)。一切似乎都安装在Python2.7文件夹中 - python3内核无法找到它吗?以下是一些有用的日志和错误消息:

print(platform.python_version())
!pip install keras==2.1.1
!pip show keras
import keras

3.5.2
Requirement already satisfied: keras==2.1.1 in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: pyyaml in /usr/local/lib/python2.7/dist-packages (from keras==2.1.1)
Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python2.7/dist-packages (from keras==2.1.1)
Requirement already satisfied: scipy>=0.14 in /usr/local/lib/python2.7/dist-packages (from keras==2.1.1)
Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python2.7/dist-packages (from keras==2.1.1)
Name: Keras
Version: 2.1.1
Summary: Deep Learning for Python
Home-page: https://github.com/fchollet/keras
Author: Francois Chollet
Author-email: francois.chollet@gmail.com
License: MIT
Location: /usr/local/lib/python2.7/dist-packages
Requires: pyyaml, six, scipy, numpy
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-49-02979b1fc374> in <module>()
  2 get_ipython().system('pip install keras==2.1.1')
  3 get_ipython().system('pip show keras')
----> 4 import keras

ImportError: No module named 'keras'

2 个答案:

答案 0 :(得分:1)

尝试pip3 install keras==2.1.1

pip将使用默认版本的pip安装它,该版本适用于Python 2.7(您可以查看pip -V

pip3将始终是pip的Python 3版本。

答案 1 :(得分:0)

我遇到了类似的问题,在我的情况下,解决方案与Chris Meyers的建议相反:我需要使用pip而不是pip3

仔细检查发现,pip3正在将我需要的模块安装到python3.5文件夹中,而我的内核正在查看python3.7