google-cloud-platformgcp-ai-platform-notebook

How do you set up a Python 3.8 kernel on GCP's AI Platform JupyterLab instances?


My goal is to be able to start a JupyterNotebook in JupyterLab with Python3.8


Solution

  • Update Python version to 3.8 in GCP AI Platform Jupyter Notebooks

    AI Platform Notebooks environments are provided by container images that you select when creating the instance. In this page you will see the available container image types.

    In order to specify the container image to run on the notebook you can either choose between using one of the list provided by Google Cloud mentioned above or in case that none of them comes with Python 3.8, you can create a derivative container based on one of the standard AI Platform images and edit the Dockerfile in order to set the Python 3.8 installation command.

    To test it out I have made a small modification to a provided container image to incorporate a Python 3.8 kernel in JupyterLab. In order to do it I have created a Dockerfile that does the following:

    Once the image has been built and pushed to Google Container Registry, you will be able to create an AI Platform Jupyter Notebook with the new kernel.

    The code is the following:

    FROM gcr.io/deeplearning-platform-release/tf-gpu:latest
    RUN apt-get update -y \
    && apt-get upgrade -y \
    && apt-get install -y apt-transport-https \
    && apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget libbz2-dev \
    && wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
    RUN tar xzf Python-3.8.0.tgz \
    && echo Getting inside folder \
    && cd Python-3.8.0 \
    && ./configure --enable-optimizations \
    && make -j 8 \
    && make altinstall \
    && apt-get install -y python3-venv \
    && echo Creating environment... \
    && python3.8 -m venv testenv \
    && echo Activating environment... \
    && . testenv/bin/activate \
    && echo Installing jupyter... \
    && pip install jupyter \
    && pip install ipython \
    && apt-get update -y \
    && apt-get upgrade -y \
    && ipython kernel install --name "Python3.8" --user
    

    In case you need it, you can also specify a custom image that will allow you to customize the environment for your specific needs. Take into account that the product is in Beta and might change or have limited support.