0

I want to change the python version on my Google Colab. Currently, it's running python 3.7:

[In]: ! python --version
[Out]: Python 3.7.13

I want python 3.10, so I followed the instructions in this post:

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

Here, a list is printed, and I choose python 3.10. Then

! sudo apt install python3-pip

Now, when I query the python version, it shows 3.10:

[In]: ! python --version
[Out]: Python 3.10.6

So far so good! BUT, now there are two problems:

  1. pip seems to be completely broken; I can't pip install anything, e.g. both !pip install gym and !pip3 install gym give the following error:
AttributeError: module 'collections' has no attribute 'MutableMapping'
  1. Python version shows 3.10, but seems to be still 3.7, as newer syntax throws syntax error, e.g.:
[In]: (a := 3)
[Out]: SyntaxError: invalid syntax
[In]: a: list[int] = [1]
[Out]: TypeError: 'type' object is not subscriptable
Qunatized
  • 197
  • 1
  • 9
  • Does this answer your question? [Getting AttributeError: module 'collections' has no attribute 'MutableMapping' while using any pip3 command on linux Python 3.10](https://stackoverflow.com/questions/69512672/getting-attributeerror-module-collections-has-no-attribute-mutablemapping-w) – Nick ODell Aug 12 '22 at 02:25
  • @NickODell No unfortunately it doesn't. – Qunatized Aug 12 '22 at 02:36

2 Answers2

0

you must downgrade python.

Deprecated since version 3.3, will be removed in version 3.10: Moved Collections Abstract Base Classes to the collections.abc module. For backwards compatibility, they continue to be visible in this module through Python 3.9.

Ref. https://docs.python.org/3.9/library/collections.html

lh.P
  • 31
  • 2
  • 2
    What do you mean? I want to UPGRADE from 3.7 to 3.10! – Qunatized Aug 12 '22 at 04:27
  • 1
    3.10 version cannot call collections.MutableMapping. It's changed to collections.abc.MutableMapping. Have several ways to fix that but it seems hard on colab. – lh.P Aug 12 '22 at 07:33
0

2)I had the same problem (used the same code to change python version it showed like the version has changed but in reality the default version was being used) this answer helped me:

https://stackoverflow.com/a/71512719/4240783

1)If the answer above didn't help maybe this might be useful with pip installation:

!sudo apt install python3-pip
!sudo apt-get install --reinstall python3.10-distutils
!python3 -m pip install --upgrade --force-reinstall pip
pluto2111
  • 1
  • 2