Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use Python 3.5 instead of 3.6?

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?

like image 854
Timothy Kassis Avatar asked Sep 23 '18 15:09

Timothy Kassis


People also ask

How do I switch between Python versions?

Yes, you should be able to switch between python versions. As a standard, it is recommended to use the python3 command or python3. 7 to select a specific version. The py.exe launcher will automatically select the most recent version of Python you've installed.

Is Python 3.6 still supported?

Following the release of Python 3.9, Vercel is deprecating support for Python 3.6 which reached end of life last year. On July 18th 2022, new deployments targeting Python 3.6 will fail with an error message.

How do I install a different version of Python?

Install that version using "make install". Install all other versions using "make altinstall". For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.

Does Python 3.5 have pip?

Pip Documentation Here we see that pip 19.1. 1 is compatible with Python 3.5.


3 Answers

The only way to vary the Python 3 version is to connect to a local runtime.

like image 137
Craig Citro Avatar answered Oct 18 '22 01:10

Craig Citro


You cannot directly change the environment for the notebook.

After hours of exploration, I found a solution:

  1. Initialize a Ngork server in the Colaboratory notebook.
  2. connect to the Ngork server from a local terminal using SSH (or use any editor which supports SSH connections)
  3. Install the required Python version using the terminal.
  4. Install virtualenv.
  5. Create a virtual environment by specifying the Python version installed.
  6. Activate the environment.
  7. 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.

like image 20
Eswar Chitirala Avatar answered Oct 18 '22 02:10

Eswar Chitirala


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.

like image 31
ngrislain Avatar answered Oct 18 '22 02:10

ngrislain