How to upgrade Google Cloud AI Platform Jupyter Lab to Python 3.7+

[亡魂溺海] 提交于 2021-02-07 04:22:11

问题


Google Cloud Platform's AI Platform has convenient deployment of Jupyter Lab, but only for Python 2 and Python 3.5.3. How can I upgrade my instance to be able to run Python 3.7 (or higher) notebooks?


回答1:


This solution is built off of the answers in How do I install Python 3.7 in google cloud shell.

How to get python 3.7 working on Google Cloud Platform's AI Platform Notebook Instances, which comes with built-in support for JupyterLab, but is only updated to python 3.5.3:

  1. Create or use an existing Notebook instance.

  2. Click on the OPEN JUPYTERLAB button to launch JupyterLab in your brower. Within JupyterLab, open a new terminal to install as the jupyter user (File > New > Terminal). Don't SSH into your instance! Again, don't use the GCP shell.

  3. Follow these commands to install the new version of python (here is 3.7.4):

# install necessary command-line tools and packages
sudo apt-get install -y build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev \
     libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev zlib1g-dev openssl \
     libffi-dev python3-dev python3-setuptools wget liblzma-dev

#install pyenv to install python on persistent home directory

curl https://pyenv.run | bash

# add to path
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc

# install python 3.7.4 (will take a while) and make default
pyenv install 3.7.4
pyenv global 3.7.4

python -m pip install ipykernel

python -m ipykernel install --user --name python-37 --display-name "Python 3.7"
  1. Now you need to close and restart your JupyterLab instance (as in step 2). Python 3.7 should now be available in your kernel dropdown when you open any .ipynb file.

Note that you will need to re-install any packages your code depends on, like pandas and scikit-learn. Again, do the installing from the Terminal window. For example:

pip install pandas scikit-learn joblib imbalanced-learn pymongo matplotlib nltk


来源:https://stackoverflow.com/questions/59867635/how-to-upgrade-google-cloud-ai-platform-jupyter-lab-to-python-3-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!