I tried a few things from previous answers/comments, including this suggestion: https://askubuntu.com/a/1393389/879117
to no avail.
Also, I removed and re-added the deadsnake repository in the process.
This worked for me on Ubuntu 22.04 LTS:
- Purge Python 3.12
- Reinstall it if required
- Then check if it worked
Purge Python 3.12
Purge the listed packages with good old apt, no magic
$ sudo apt remove --purge python3.12 python3.12-dev libpython3.12-stdlib libpython3.12-minimal libpython3.12
$ sudo apt autoremove
$ sudo apt --fix-broken install
$ sudo apt remove --purge python3.12 python3.12-dev libpython3.12-stdlib libpython3.12-minimal libpython3.12 &&
sudo apt autoremove &&
sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
python3.12-lib2to3
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED
idle-python3.12* libpython3.12* libpython3.12-dev* libpython3.12-minimal* libpython3.12-stdlib* libpython3.12-testsuite* python3.12* python3.12-dev* python3.12-examples* python3.12-full* python3.12-gdbm* python3.12-tk* python3.12-venv*
0 to upgrade, 0 to newly install, 13 to remove and 0 not to upgrade.
9 not fully installed or removed.
After this operation, 97.5 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 419466 files and directories currently installed.)
Removing python3.12-full (3.12.8-1+jammy1) ...
Removing idle-python3.12 (3.12.8-1+jammy1) ...
Removing libpython3.12-testsuite (3.12.8-1+jammy1) ...
Removing python3.12-venv (3.12.8-1+jammy1) ...
Removing python3.12-tk:amd64 (3.12.8-1+jammy1) ...
Removing python3.12-dev (3.12.8-1+jammy1) ...
Removing python3.12-examples (3.12.8-1+jammy1) ...
Removing python3.12-gdbm:amd64 (3.12.8-1+jammy1) ...
Removing libpython3.12-dev:amd64 (3.12.8-1+jammy1) ...
Removing libpython3.12:amd64 (3.12.8-1+jammy1) ...
Removing python3.12 (3.12.8-1+jammy1) ...
Removing libpython3.12-stdlib:amd64 (3.12.8-1+jammy1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
(Reading database ... 416223 files and directories currently installed.)
Purging configuration files for libpython3.12-stdlib:amd64 (3.12.8-1+jammy1) ...
Purging configuration files for python3.12-venv (3.12.8-1+jammy1) ...
Purging configuration files for libpython3.12-minimal:amd64 (3.12.7-1+jammy1) ...
dpkg: warning: while removing libpython3.12-minimal:amd64, directory '/etc/python3.12' not empty so not removed
Purging configuration files for idle-python3.12 (3.12.8-1+jammy1) ...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED
python3.12-lib2to3
0 to upgrade, 0 to newly install, 1 to remove and 0 not to upgrade.
After this operation, 451 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 416221 files and directories currently installed.)
Removing python3.12-lib2to3 (3.12.8-1+jammy1) ...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
Reinstall Python 3.12
Following that ran
sudo apt update && sudo apt upgrade
sudo apt install python3.12-dev
$ sudo apt install python3.12-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libpython3.12 libpython3.12-dev
The following NEW packages will be installed
libpython3.12 libpython3.12-dev python3.12-dev
0 to upgrade, 3 to newly install, 0 to remove and 0 not to upgrade.
Need to get 6,184 kB/8,565 kB of archives.
After this operation, 38.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy/main amd64 libpython3.12-dev amd64 3.12.8-1+jammy1 [5,686 kB]
Get:2 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy/main amd64 python3.12-dev amd64 3.12.8-1+jammy1 [498 kB]
Fetched 6,184 kB in 12s (529 kB/s)
Selecting previously unselected package libpython3.12:amd64.
(Reading database ... 419211 files and directories currently installed.)
Preparing to unpack .../libpython3.12_3.12.8-1+jammy1_amd64.deb ...
Unpacking libpython3.12:amd64 (3.12.8-1+jammy1) ...
Selecting previously unselected package libpython3.12-dev:amd64.
Preparing to unpack .../libpython3.12-dev_3.12.8-1+jammy1_amd64.deb ...
Unpacking libpython3.12-dev:amd64 (3.12.8-1+jammy1) ...
Selecting previously unselected package python3.12-dev.
Preparing to unpack .../python3.12-dev_3.12.8-1+jammy1_amd64.deb ...
Unpacking python3.12-dev (3.12.8-1+jammy1) ...
Setting up libpython3.12:amd64 (3.12.8-1+jammy1) ...
Setting up libpython3.12-dev:amd64 (3.12.8-1+jammy1) ...
Setting up python3.12-dev (3.12.8-1+jammy1) ...
Processing triggers for man-db (2.10.2-1) ...
Check install
Finally, for good measure, I attempted a Python 3.12 full upgrade with
sudo apt full-upgrade python3.12
which failed before the fix
$ sudo apt full-upgrade python3.12
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3.12 is already the newest version (3.12.8-1+jammy1).
python3.12 set to manually installed.
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
libimage-magick-perl libheif1 imagemagick libavcodec-extra libpathplan4
graphviz libavdevice58 libgvpr2 libgvc6 ffmpeg libopenexr25
libmagick++-6.q16-8 libpostproc55 libcgraph6 libmagickcore-6.q16-6-extra
libsoup-3.0-0 libcdt5 libimage-magick-q16-perl libmagickwand-6.q16-6
libavcodec-extra58 libavutil56 imagemagick-6.q16 libswscale5
libmagickcore-6.q16-6 libgsl27 liblab-gamut1 libswresample3
imagemagick-6-common libsoup-3.0-common libavformat58 libgslcblas0
libde265-0 libavfilter7
Learn more about Ubuntu Pro at https://ubuntu.com/pro
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.