Downgrade Python 3.10 to 3.9 in google colab

3.8k Views Asked by At

It looks like there is a compatibility issue with PyTorch and Python 3.10 when I want to use google Colab. I need to use !pip install torch==1.8 torchvision==0.9 but this problem don't let me.
I should do Downgrading.

I need to get code to downgarde Python version.

2

There are 2 best solutions below

2
Qmachine On

I have had a similar problem. It seems to be due to an 'upgrade' pushed to Colabs. I think this addresses that 'upgrade': https://github.com/googlecolab/colabtools/issues/3646#issuecomment-1570238781

There's maybe more to it than this, but this is how I downgraded python in my colabs notebook:

!sudo apt-get update -y
!sudo apt-get install python3.8 -y
!echo 2 | sudo update-alternatives --config python3 #'echo 2' auto-inputs '2' so that it doesn't have to be done manually

I hope this helps. Good luck.

0
Omid Ostovari On

Below is a method to downgrade Python. But you should note that every time you want to use the conda environment to install or work with it, you must first use this script ! source activate env_name; or easily use %%bash first of cells to activate it, then write the command you want exactly after this script.

Step 1:

! python --version

Step 2:

!pip install -q condacolab

import condacolab

condacolab.install()

Step 3:

!conda --version

Step 4:

you should choose a python version from the output of this code and replace to PYTHON_VERSION in next step: !conda search python

Step 5:

! conda create -n env_name python=PYTHON_VERSION # PYTHON_VERSION can be 3.9 or any other releas

Step 6:

you should create a requirements.txt file and place name of all packages which you need to install on it.

Step 7:

! source activate env_name; python --version; pip -V; pip install -r requirements.txt