I have a code which works in python3.5 but will throw errors in python>3.5
but with !python --version
in google colab return python 3.6.9, is there any way I can force google colab to use 3.5.
I found some solutions in Stackoverflow which asked me to use local run time which won't be useful for me because I don't have enough computational resources in my local machine.
Asked
Active
Viewed 4,830 times
0

Eswar Chitirala
- 486
- 6
- 14
-
1https://stackoverflow.com/questions/52467489/is-there-a-way-to-use-python-3-5-instead-of-3-6 According to the answer, No. But you can use a local runtime https://research.google.com/colaboratory/local-runtimes.html – Sudaraka Jayathilaka Jan 17 '20 at 13:48
-
Actually, you can, see: https://stackoverflow.com/a/71511943/1854249 – ngrislain Mar 17 '22 at 15:17
1 Answers
1
There is a way to use any version of python you want, let's say python3.5, 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": "py35",
"display_name": "Python 3.5"
}
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 py35 kernel, so it use normal python3 kernel.
You need to install a python 3.5, the google-colab
package and the ipykernel
under the name you defined above: "py35":
!apt-get install python3.5
!curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
!python3.5 get-pip.py
!python3.5 -m pip install jupyter google-colab
!python3.5 -m ipykernel install --name "py35" --user
Reload the page, and test the version is correct:
import sys
print("User Current Version:-", sys.version)

ngrislain
- 944
- 12
- 19
-
Please [don't post duplicate answers](https://meta.stackexchange.com/q/104227). If the questions are the same, pick the best one to answer and then flag the other(s) as duplicates. If they're not the same, then tailor your answer to the specifics of each question. – ChrisF Mar 17 '22 at 13:28