简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM