Timothy Kassis
Timothy Kassis

Reputation: 191

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?

Upvotes: 7

Views: 18898

Answers (3)

ngrislain
ngrislain

Reputation: 1072

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.

Upvotes: 5

Eswar Chitirala
Eswar Chitirala

Reputation: 552

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.

Upvotes: 4

Craig Citro
Craig Citro

Reputation: 6625

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

Upvotes: 4

Related Questions