How to upgrade to the latest Python version on Linux Ubuntu Debian Mint 3.11

A lot of developers want to go to 3.11 because of the speed improvements, but most distros never have the latest Python version.

Using the deadsnakes third party repo is the easiest way aside from compiling it yourself (which is safer and recommended):

Step 1 - Add the repo

apt-add-repository ppa:deadsnakes/ppa

If you get an error about requests then install it:

pip3 install requests
Traceback (most recent call last):
  File "/usr/lib/linuxmint/mintSources/mintSources.py", line 11, in
    import requests
ModuleNotFoundError: No module named 'requests'

pip3 install requests
Collecting requests
  Downloading https://files.pythonhosted.org/packages/2d/61/08076519c80041bc0ffa1a8af0cbd3bf3e2b62af10435d269a9d0f40564d/requests-2.27.1-py2.py3-none-any.whl (63kB)
    100% |████████████████████████████████| 71kB 4.5MB/s
Collecting certifi>=2017.4.17 (from requests)
  Downloading https://files.pythonhosted.org/packages/4c/dd/2234eab22353ffc7d94e8d13177aaa050113286e93e7b40eae01fbf7c3d9/certifi-2023.7.22-py3-none-any.whl (158kB)
    100% |████████████████████████████████| 163kB 5.0MB/s
Collecting urllib3<1.27,>=1.21.1 (from requests)
  Downloading https://files.pythonhosted.org/packages/48/fe/a5c6cc46e9fe9171d7ecf0f33ee7aae14642f8d74baa7af4d7840f9358be/urllib3-1.26.17-py2.py3-none-any.whl (143kB)
    100% |████████████████████████████████| 153kB 9.2MB/s
Requirement already satisfied: idna<4,>=2.5; python_version >= "3" in /usr/lib/python3/dist-packages (from requests)
Collecting charset-normalizer~=2.0.0; python_version >= "3" (from requests)
  Downloading https://files.pythonhosted.org/packages/06/b3/24afc8868eba069a7f03650ac750a778862dc34941a4bebeb58706715726/charset_normalizer-2.0.12-py3-none-any.whl
Installing collected packages: certifi, urllib3, charset-normalizer, requests
Successfully installed certifi-2023.7.22 charset-normalizer-2.0.12 requests-2.27.1 urllib3-1.26.17
 

Installation of the deadsnakes ppa

Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
You are about to add the following PPA:
 This PPA contains more recent Python versions packaged for Ubuntu.

Disclaimer: there's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

Update Note
===========
Please use this repository instead of ppa:fkrull/deadsnakes.

Reporting Issues
================

Issues can be reported in the master issue tracker at:
https://github.com/deadsnakes/issues/issues

Supported Ubuntu and Python Versions
====================================

- Ubuntu 20.04 (focal) Python3.5 - Python3.7, Python3.9 - Python3.11
- Ubuntu 22.04 (jammy) Python3.7 - Python3.9, Python3.11
- Note: Python2.7 (all), Python 3.8 (focal), Python 3.10 (jammy) are not provided by deadsnakes as upstream ubuntu provides those packages.

Why some packages aren't built:
- Note: for focal, older python versions require libssl<1.1 so they are not currently built
- Note: for jammy, older python versions requre libssl<3 so they are not currently built
- If you need these, reach out to asottile to set up a private ppa

The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.

Packages
========

The packages provided here are loosely based on the debian upstream packages with some modifications to make them more usable as non-default pythons and on ubuntu.  As such, the packages follow debian's patterns and often do not include a full python distribution with just `apt install python#.#`.  Here is a list of packages that may be useful along with the default install:

- `python#.#-dev`: includes development headers for building C extensions
- `python#.#-venv`: provides the standard library `venv` module
- `python#.#-distutils`: provides the standard library `distutils` module
- `python#.#-lib2to3`: provides the `2to3-#.#` utility as well as the standard library `lib2to3` module
- `python#.#-gdbm`: provides the standard library `dbm.gnu` module
- `python#.#-tk`: provides the standard library `tkinter` module

Third-Party Python Modules
==========================

Python modules in the official Ubuntu repositories are packaged to work with the Python interpreters from the official repositories. Accordingly, they generally won't work with the Python interpreters from this PPA. As an exception, pure-Python modules for Python 3 will work, but any compiled extension modules won't.

To install 3rd-party Python modules, you should use the common Python packaging tools.  For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide:
https://packaging.python.org/installing/

Sources
=======
The package sources are available at:
https://github.com/deadsnakes/

Nightly Builds
==============

For nightly builds, see ppa:deadsnakes/nightly https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly
 More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Press Enter to continue or Ctrl+C to cancel

Executing: /tmp/apt-key-gpghome.grYwz5aXqY/gpg.1.sh --keyserver hkps://keyserver.ubuntu.com:443 --recv-keys F23C5A6CF475977595C89F51BA6932366A755776
gpg: key BA6932366A755776: public key "Launchpad PPA for deadsnakes" imported
gpg: Total number processed: 1
gpg:               imported: 1

Install Python 3.11

apt update

apt install python3.11

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libpython3.11-minimal libpython3.11-stdlib python3.11-minimal
Suggested packages:
  python3.11-venv binfmt-support
The following NEW packages will be installed:
  libpython3.11-minimal libpython3.11-stdlib python3.11 python3.11-minimal
0 upgraded, 4 newly installed, 0 to remove and 1 not upgraded.
Need to get 5570 kB of archives.
After this operation, 21.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.11-minimal amd64 3.11.5-1+focal1 [851 kB]
Get:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.11-minimal amd64 3.11.5-1+focal1 [2298 kB]
Get:3 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.11-stdlib amd64 3.11.5-1+focal1 [1801 kB]
Get:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.11 amd64 3.11.5-1+focal1 [620 kB]
Fetched 5570 kB in 4s (1307 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 4.)
debconf: falling back to frontend: Readline
Selecting previously unselected package libpython3.11-minimal:amd64.
(Reading database ... 20150 files and directories currently installed.)
Preparing to unpack .../libpython3.11-minimal_3.11.5-1+focal1_amd64.deb ...
Unpacking libpython3.11-minimal:amd64 (3.11.5-1+focal1) ...
Selecting previously unselected package python3.11-minimal.
Preparing to unpack .../python3.11-minimal_3.11.5-1+focal1_amd64.deb ...
Unpacking python3.11-minimal (3.11.5-1+focal1) ...
Selecting previously unselected package libpython3.11-stdlib:amd64.
Preparing to unpack .../libpython3.11-stdlib_3.11.5-1+focal1_amd64.deb ...
Unpacking libpython3.11-stdlib:amd64 (3.11.5-1+focal1) ...
Selecting previously unselected package python3.11.
Preparing to unpack .../python3.11_3.11.5-1+focal1_amd64.deb ...
Unpacking python3.11 (3.11.5-1+focal1) ...
Setting up libpython3.11-minimal:amd64 (3.11.5-1+focal1) ...
Setting up python3.11-minimal (3.11.5-1+focal1) ...
Setting up libpython3.11-stdlib:amd64 (3.11.5-1+focal1) ...
Setting up python3.11 (3.11.5-1+focal1) ...
Processing triggers for mime-support (3.64ubuntu1) ...

You may have to manually invoke as you'll see in Ubuntu 20 it uses the default 3.8 still:

ls -al /usr/bin/python3
lrwxrwxrwx 1 root root 9 Mar 13  2020 /usr/bin/python3 -> python3.8
 

Or if you can take the risk in a testing environment, change the symlink for python3 to point to python3.11

pip won't work either, so you can use venv or do this (if it's a testing/dev environment):

wget https://bootstrap.pypa.io/get-pip.py

python3.11 get-pip.py
Collecting pip
  Obtaining dependency information for pip from https://files.pythonhosted.org/packages/50/c2/e06851e8cc28dcad7c155f4753da8833ac06a5c704c109313b8d5a62968a/pip-23.2.1-py3-none-any.whl.metadata
  Downloading pip-23.2.1-py3-none-any.whl.metadata (4.2 kB)
Downloading pip-23.2.1-py3-none-any.whl (2.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 36.3 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.0.2
    Uninstalling pip-20.0.2:
      Successfully uninstalled pip-20.0.2
Successfully installed pip-23.2.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv



Tags:

upgrade, python, linux, ubuntu, debian, mint, developers, improvements, distros, deadsnakes, repo, easiest, compiling, recommended, apt, repository, ppa, requests, install, pip, traceback, quot, usr, lib, linuxmint, mintsources, py, module, import, modulenotfounderror, collecting, downloading, https, pythonhosted, org, packages, bc, ffa, af, cbd, bf, whl, kb, mb, certifi, dd, eab, ffc, aaa, eae, fbf, urllib, fe, cc, ecf, ee, aae, baa, requirement, idna, python_version, dist, charset, normalizer, afc, eba, ac, dc, bebeb, charset_normalizer, installing, collected, successfully, installed, installation, unable, init, server, contains, versions, packaged, disclaimer, timely, updates, update, fkrull, reporting, reported, tracker, github, supported, focal, jammy, provided, upstream, provides, aren, libssl, currently, requre, asottile, loosely, modifications, usable, default, pythons, patterns, dev, includes, headers, extensions, venv, distutils, utility, gdbm, dbm, gnu, tk, tkinter, modules, repositories, interpreters, accordingly, generally, exception, compiled, extension, rd, packaging, introduction, ecosystem, refer, user, sources, nightly, builds, launchpad, archive, info, ctrl, executing, tmp, gpghome, grywz, axqy, gpg, sh, keyserver, hkps, recv, cf, imported, processed,

Latest Articles

  • qemu: could not load PC BIOS 'bios-256k.bin' solution
  • Proxmox How To Custom Partition During Install
  • Hyper-V Linux VM Boots to Black Screen, Storage, NIC Not Found Issues
  • Ubuntu Mint How to Fix Missing/Broken /dev and /dev/pts which causes terminal to immediately close exit and not work
  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution
  • Ubuntu Linux Mint Debian Redhat Youtube Cannot Play HD or 4K videos, dropped frames or high CPU usage with Nvidia or AMD Driver
  • hostapd example configuration for high speed AC on 5GHz using WPA2
  • hostapd how to enable and use WPS to connect wireless devices like printers
  • Dell Server Workstation iDRAC Dead after Firmware Update Solution R720, R320, R730
  • Cloned VM/Server/Computer in Linux won't boot and goes to initramfs busybox Solution
  • How To Add Windows 7 8 10 11 to GRUB Boot List Dual Booting
  • How to configure OpenDKIM on Linux with Postfix and setup bind zonefile
  • Debian Ubuntu 10/11/12 Linux how to get tftpd-hpa server setup tutorial
  • efibootmgr: option requires an argument -- 'd' efibootmgr version 15 grub-install.real: error: efibootmgr failed to register the boot entry: Operation not permitted.
  • Apache Error Won't start SSL Cert Issue Solution Unable to configure verify locations for client authentication SSL Library Error: 151441510 error:0906D066:PEM routines:PEM_read_bio:bad end line SSL Library Error: 185090057 error:0B084009:x509 certif
  • Linux Debian Mint Ubuntu Bridge br0 gets random IP
  • redis requirements
  • How to kill a docker swarm
  • docker swarm silly issues