Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Python 3.10 in Google Colab?

I would like to use the Structural Pattern Matching feature from Python 3.10 in Google Colab so using the commands

!sudo apt-get install python3.10
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
!sudo update-alternatives --set python3 /usr/bin/python3.10

I was able to make !python --version output 3.10.0, but the print(sys.version) still outputs 3.7.12 in code cells and so the match cases statement raises SyntaxError

number = 1

match number:
    case 0:
        print("Error")
    case _:
        print(number)

Is there any way to make this work?

like image 835
pedrolmcastro Avatar asked Jan 18 '26 07:01

pedrolmcastro


1 Answers

You can use this notebook.

  • make a copy of it
  • run the first cell
  • reload (Ctrl + R, or Cmd + R)
  • run the second cell

See this video demo by 1littlecoder.

like image 52
korakot Avatar answered Jan 20 '26 19:01

korakot