Tuesday, August 09, 2022

[How To] Upgrade to Python 3.9 in Google Colab


Google Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows anybody to write and execute arbitrary python code through the browser and is especially well suited to machine learning, data analysis, and education. More technically, Colab is a hosted Jupyter notebook service that requires no setup to use while providing access free of charge to computing resources, including GPUs.

By default, it starts the runtime with Python version 3.7. If you want to upgrade the version in your current notebook, then follow these steps in the given order:

1) !python --version
Python 3.7.13

2) !sudo apt-get update -y
Get:1 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic InRelease [15.9 kB]
Hit:2 http://ppa.launchpad.net/cran/libgit2/ubuntu bionic InRelease
Get:3 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/ InRelease [3,626 B]
Get:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic InRelease [15.9 kB]
Hit:5 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu bionic InRelease
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:7 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:8 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:9 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic/main Sources [2,077 kB]
Ign:10 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64  InRelease
Get:11 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  InRelease [1,581 B]
Hit:12 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64  Release
Get:13 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic/main amd64 Packages [1,064 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:15 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 Packages [45.3 kB]
Get:16 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64  Packages [902 kB]
Get:18 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2,905 kB]
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [2,306 kB]
Get:20 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [3,336 kB]
Get:21 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,528 kB]
Fetched 14.5 MB in 9s (1,578 kB/s)
Reading package lists... Done

3) !sudo apt-get install --upgrade python3.9 python3-dev python3-pip python3.9-distutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-dev is already the newest version (3.6.7-1~18.04).
python3-dev set to manually installed.
The following package was automatically installed and is no longer required:
libnvidia-common-460
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libpython3.9-minimal libpython3.9-stdlib python-pip-whl python3-asn1crypto
python3-cffi-backend python3-crypto python3-cryptography python3-idna
python3-keyring python3-keyrings.alt python3-pkg-resources
python3-secretstorage python3-setuptools python3-six python3-wheel
python3-xdg python3.9-lib2to3 python3.9-minimal
Suggested packages:
python-crypto-doc python-cryptography-doc python3-cryptography-vectors
gnome-keyring libkf5wallet-bin gir1.2-gnomekeyring-1.0
python-secretstorage-doc python-setuptools-doc python3.9-venv binfmt-support
The following NEW packages will be installed:
libpython3.9-minimal libpython3.9-stdlib python-pip-whl python3-asn1crypto
python3-cffi-backend python3-crypto python3-cryptography python3-idna
python3-keyring python3-keyrings.alt python3-pip python3-pkg-resources
python3-secretstorage python3-setuptools python3-six python3-wheel
python3-xdg python3.9 python3.9-distutils python3.9-lib2to3
python3.9-minimal
0 upgraded, 21 newly installed, 0 to remove and 26 not upgraded.
Need to get 8,111 kB of archives.
After this operation, 29.2 MB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 libpython3.9-minimal amd64 3.9.13-1+bionic1 [805 kB]
Get:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 python3.9-minimal amd64 3.9.13-1+bionic1 [1,937 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 python-pip-whl all 9.0.1-2.3~ubuntu1.18.04.5 [1,653 kB]
Get:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 libpython3.9-stdlib amd64 3.9.13-1+bionic1 [1,679 kB]
Get:5 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 python3.9 amd64 3.9.13-1+bionic1 [492 kB]
Get:6 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 python3.9-lib2to3 all 3.9.13-1+bionic1 [125 kB]
Get:7 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 python3.9-distutils all 3.9.13-1+bionic1 [190 kB]
Get:8 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-asn1crypto all 0.24.0-1 [72.8 kB]
Get:9 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-cffi-backend amd64 1.11.5-1 [64.6 kB]
Get:10 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-crypto amd64 2.6.1-8ubuntu2 [244 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-idna all 2.6-1 [32.5 kB]
Get:12 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-six all 1.11.0-2 [11.4 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-cryptography amd64 2.1.4-1ubuntu1.4 [220 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-secretstorage all 2.3.1-2 [12.1 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-keyring all 10.6.0-1 [26.7 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-keyrings.alt all 3.0-1 [16.6 kB]
Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 python3-pip all 9.0.1-2.3~ubuntu1.18.04.5 [114 kB]
Get:18 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-pkg-resources all 39.0.1-2 [98.8 kB]
Get:19 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-setuptools all 39.0.1-2 [248 kB]
Get:20 http://archive.ubuntu.com/ubuntu bionic/universe amd64 python3-wheel all 0.30.0-0.2 [36.5 kB]
Get:21 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-xdg all 0.25-4ubuntu1.1 [31.3 kB]
Fetched 8,111 kB in 4s (2,218 kB/s)
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76, <> line 21.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:
Selecting previously unselected package libpython3.9-minimal:amd64.
(Reading database ... 155680 files and directories currently installed.)
Preparing to unpack .../00-libpython3.9-minimal_3.9.13-1+bionic1_amd64.deb ...
Unpacking libpython3.9-minimal:amd64 (3.9.13-1+bionic1) ...
Selecting previously unselected package python3.9-minimal.
Preparing to unpack .../01-python3.9-minimal_3.9.13-1+bionic1_amd64.deb ...
Unpacking python3.9-minimal (3.9.13-1+bionic1) ...
Selecting previously unselected package libpython3.9-stdlib:amd64.
Preparing to unpack .../02-libpython3.9-stdlib_3.9.13-1+bionic1_amd64.deb ...
Unpacking libpython3.9-stdlib:amd64 (3.9.13-1+bionic1) ...
Selecting previously unselected package python-pip-whl.
Preparing to unpack .../03-python-pip-whl_9.0.1-2.3~ubuntu1.18.04.5_all.deb ...
Unpacking python-pip-whl (9.0.1-2.3~ubuntu1.18.04.5) ...
Selecting previously unselected package python3-asn1crypto.
Preparing to unpack .../04-python3-asn1crypto_0.24.0-1_all.deb ...
Unpacking python3-asn1crypto (0.24.0-1) ...
Selecting previously unselected package python3-cffi-backend.
Preparing to unpack .../05-python3-cffi-backend_1.11.5-1_amd64.deb ...
Unpacking python3-cffi-backend (1.11.5-1) ...
Selecting previously unselected package python3-crypto.
Preparing to unpack .../06-python3-crypto_2.6.1-8ubuntu2_amd64.deb ...
Unpacking python3-crypto (2.6.1-8ubuntu2) ...
Selecting previously unselected package python3-idna.
Preparing to unpack .../07-python3-idna_2.6-1_all.deb ...
Unpacking python3-idna (2.6-1) ...
Selecting previously unselected package python3-six.
Preparing to unpack .../08-python3-six_1.11.0-2_all.deb ...
Unpacking python3-six (1.11.0-2) ...
Selecting previously unselected package python3-cryptography.
Preparing to unpack .../09-python3-cryptography_2.1.4-1ubuntu1.4_amd64.deb ...
Unpacking python3-cryptography (2.1.4-1ubuntu1.4) ...
Selecting previously unselected package python3-secretstorage.
Preparing to unpack .../10-python3-secretstorage_2.3.1-2_all.deb ...
Unpacking python3-secretstorage (2.3.1-2) ...
Selecting previously unselected package python3-keyring.
Preparing to unpack .../11-python3-keyring_10.6.0-1_all.deb ...
Unpacking python3-keyring (10.6.0-1) ...
Selecting previously unselected package python3-keyrings.alt.
Preparing to unpack .../12-python3-keyrings.alt_3.0-1_all.deb ...
Unpacking python3-keyrings.alt (3.0-1) ...
Selecting previously unselected package python3-pip.
Preparing to unpack .../13-python3-pip_9.0.1-2.3~ubuntu1.18.04.5_all.deb ...
Unpacking python3-pip (9.0.1-2.3~ubuntu1.18.04.5) ...
Selecting previously unselected package python3-pkg-resources.
Preparing to unpack .../14-python3-pkg-resources_39.0.1-2_all.deb ...
Unpacking python3-pkg-resources (39.0.1-2) ...
Selecting previously unselected package python3-setuptools.
Preparing to unpack .../15-python3-setuptools_39.0.1-2_all.deb ...
Unpacking python3-setuptools (39.0.1-2) ...
Selecting previously unselected package python3-wheel.
Preparing to unpack .../16-python3-wheel_0.30.0-0.2_all.deb ...
Unpacking python3-wheel (0.30.0-0.2) ...
Selecting previously unselected package python3-xdg.
Preparing to unpack .../17-python3-xdg_0.25-4ubuntu1.1_all.deb ...
Unpacking python3-xdg (0.25-4ubuntu1.1) ...
Selecting previously unselected package python3.9.
Preparing to unpack .../18-python3.9_3.9.13-1+bionic1_amd64.deb ...
Unpacking python3.9 (3.9.13-1+bionic1) ...
Selecting previously unselected package python3.9-lib2to3.
Preparing to unpack .../19-python3.9-lib2to3_3.9.13-1+bionic1_all.deb ...
Unpacking python3.9-lib2to3 (3.9.13-1+bionic1) ...
Selecting previously unselected package python3.9-distutils.
Preparing to unpack .../20-python3.9-distutils_3.9.13-1+bionic1_all.deb ...
Unpacking python3.9-distutils (3.9.13-1+bionic1) ...
Setting up python-pip-whl (9.0.1-2.3~ubuntu1.18.04.5) ...
Setting up python3-cffi-backend (1.11.5-1) ...
Setting up python3-crypto (2.6.1-8ubuntu2) ...
Setting up python3-idna (2.6-1) ...
Setting up python3-xdg (0.25-4ubuntu1.1) ...
Setting up python3-six (1.11.0-2) ...
Setting up python3-wheel (0.30.0-0.2) ...
Setting up python3-pkg-resources (39.0.1-2) ...
Setting up python3-asn1crypto (0.24.0-1) ...
Setting up python3-pip (9.0.1-2.3~ubuntu1.18.04.5) ...
Setting up python3.9-lib2to3 (3.9.13-1+bionic1) ...
Setting up python3-setuptools (39.0.1-2) ...
Setting up libpython3.9-minimal:amd64 (3.9.13-1+bionic1) ...
Setting up python3-cryptography (2.1.4-1ubuntu1.4) ...
Setting up libpython3.9-stdlib:amd64 (3.9.13-1+bionic1) ...
Setting up python3-keyrings.alt (3.0-1) ...
Setting up python3.9-minimal (3.9.13-1+bionic1) ...
Setting up python3.9-distutils (3.9.13-1+bionic1) ...
Setting up python3.9 (3.9.13-1+bionic1) ...
Setting up python3-secretstorage (2.3.1-2) ...
Setting up python3-keyring (10.6.0-1) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

4) !sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1

5) !sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2

6) !python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/1f/2c/d9626f045e7b49a6225c6b09257861f24da78f4e5f23af2ddbdf852c99b8/pip-22.2.2-py3-none-any.whl (2.0MB)
100% |████████████████████████████████| 2.0MB 565kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.1
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-22.2.2

7) !python --version
Python 3.9.13

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.