I have a dependency for my project that requires python v3.6+. It therefore throws an error during installation via pip in a python 3 kernel, because AI Platform Notebooks ship with v3.5 by default. How can I run a GCP AI Platform Notebook with the latest version of python?
2 Answers
The answer is simpler than I thought. Since the AI notebook is a GCE instance, I simply ssh'ed into the machine, and followed the instructions here to install Python 3.7.

- 1,192
- 1
- 10
- 26
-
1Thanks for posting this Axel. I have precisely the same goal but I'm new to python and Jupyter and struggling to get all the way to the end post. I installed 3.7 as per the link you posted but how does one get the Jupyter kernel to use the 3.7 installation instead of 3.5? – Martin D Nov 29 '19 at 23:53
-
See https://stackoverflow.com/questions/53468831/how-do-i-install-python-3-7-in-google-cloud-shell – climatebrad Nov 12 '20 at 15:52
Click on AI Platform notebook name and you will reach VM Instance details page and get remote access SSH option(option will be enabled only if AI Platform notebook is running and not stopped)
Once you SSH into notebook VM , you can install using following commands: How do I install Python 3.7 in google cloud shell
# Install requirements
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
# Prepare to build
mkdir /tmp/Python37
cd /tmp/Python37
# Pull down Python 3.7, build, and install
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar xvf Python-3.7.0.tar.xz
cd /tmp/Python37/Python-3.7.0
./configure
sudo make altinstall
Now you can create kernel in notebook using below commands you can do this inside the virtual environment: Open up your terminal and enter the following line by line
virtualenv -p python3.6 py_36_env
. py_36_env/bin/activate # if . does not work then use source py_36_env/bin/activate
pip install ipykernel
python -m ipykernel install --user --name=py_36_env
jupyter notebook
Then in jupyter notebook you can select the 3.6 environment (py_36_env) from the 'New' drop down menu shown above or from the 'Kernel' drop down menu within a given jupyter notebook.

- 1,220
- 1
- 23
- 31