I need to install a library that is only compatible with Python 3.5. Is there a way to change the Python version in Colaboratory from 3.6 to 3.5?
3 Answers
There is a way to use any version of python you want 3.5 or 3.8 in this example, without having to run a kernel locally or going through an ngrok proxy.
Download the colab notebook. Open a text editor to change the kernel specification to:
"kernelspec": {
"name": "py38",
"display_name": "Python 3.8"
}
This is the same trick as the one used with Javascript, Java, and Golang.
Then upload the edited notebook to Google Drive. Open the notebook in Google Colab. It cannot find the py38 kernel, so it use normal python3 kernel.
You need to install a python 3.8, the google-colab
package and the ipykernel
under the name you defined above: "py38":
!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh
!chmod +x mini.sh
!bash ./mini.sh -b -f -p /usr/local
!conda install -q -y jupyter
!conda install -q -y google-colab -c conda-forge
!python -m ipykernel install --name "py38" --user
Reload the page, and voilà, you can test the version is correct:
import sys
print("User Current Version:-", sys.version)
A working example can be found there.

- 944
- 12
- 19
-
1I'll go and like all these answers. ^_^ – korakot Mar 17 '22 at 15:52
The only way to vary the Python 3 version is to connect to a local runtime.

- 30,738
- 21
- 105
- 131

- 6,505
- 1
- 31
- 28
-
1But this doesn't allow me to to use the processing power of colab. I can always run the code on local if I need local processing – Eswar Chitirala Dec 01 '21 at 03:43
You cannot directly change the environment for the notebook.
After hours of exploration, I found a solution:
- Initialize a Ngork server in the Colaboratory notebook.
- connect to the Ngork server from a local terminal using SSH (or use any editor which supports SSH connections)
- Install the required Python version using the terminal.
- Install virtualenv.
- Create a virtual environment by specifying the Python version installed.
- Activate the environment.
- Work in that environment from the terminal directly.
Check out Free!! GPUs on your local machine which provides to get detailed description on how to follow the steps.

- 30,738
- 21
- 105
- 131

- 486
- 6
- 14
-
I followed the steps in the link, but when I ssh, it says `ssh: Could not resolve hostname tcp://x.tcp.ngrok.io:xxxxx: nodename nor servname provided, or not known`. – Yan Yang Aug 25 '21 at 01:32
-
this looks like a problem more like your system access a ssh client. were you able to connect to any other ssh terminal. if you are able to see the terminal active in ngork account then it should be an issue on your system – Eswar Chitirala Aug 25 '21 at 05:32