如何在 GCP 的 AI 平台 JupyterLab 实例上设置 Python 3.8 内核?

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

我的目标是能够使用 Python3.8

在 JupyterLab 中启动 Jupyter Notebook

将 GCP AI Platform Jupyter Notebooks 中的 Python 版本更新为 3.8

AI Platform Notebooks 环境由您在创建实例时 select 的容器映像提供。在此页面中,您将看到可用的 container image types.

为了在笔记本上指定 运行 的容器镜像,您可以选择使用上面提到的 Google Cloud 提供的列表之一,或者 none其中一个带有 Python 3.8,您可以根据标准 AI Platform 图像之一创建 derivative container 并编辑 Docker 文件以设置 Python 3.8 安装命令。

为了测试它,我对提供的容器映像做了一个小修改,以在 JupyterLab 中包含一个 Python 3.8 内核。为此,我创建了一个执行以下操作的 Docker 文件:

  • 从最新的 tf-gpu Docker 图像创建层
  • 安装 Python 3.8 和依赖项
  • 激活 Python 3.8 环境
  • 将 Python 3.8 内核安装到 Jupyter Notebooks

构建映像并将其推送到 Google Container Registry 后,您将能够使用新内核创建 AI Platform Jupyter Notebook。

代码如下:

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

如果需要,您还可以指定一个 custom image,这样您就可以根据自己的特定需要自定义环境。考虑到该产品处于测试阶段,可能会更改或支持有限。