google-cloud-datalab

Module not found in Google Cloud DataLab


I am using Google Cloud DataLab, the ipython notebook running on Google's Cloud Compute Engine, where I have tried to install the python module keras, but the notebook claims it can't find it. I am running Python3 (and have restart the kernel after installing). Everything appears to be installed in a Python2.7 folder - could the python3 kernel not be able to find it? Here are some useful log and error messages:

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'

Solution

  • Try pip3 install keras==2.1.1

    pip will install it with the default version of pip, which is for Python 2.7 (you can check with pip -V)

    pip3 will always be the Python 3 version of pip.