16

My Ubuntu Jammy, would like upgrade Python but fail.

Do you want to continue? [O/n] O
(Reading database ... 375728 files and directories currently installed.)
Preparing to unpack .../python3.12_3.12.8-1+jammy1_amd64.deb ...
Unpacking python3.12 (3.12.8-1+jammy1) over (3.12.7-1+jammy1) ...
dpkg: error processing archive /var/cache/apt/archives/python3.12_3.12.8-1+jammy1_amd64.deb (--unpack):
trying to overwrite '/usr/bin/python3.12', which is also in package python3.12-minimal 3.12.7-1+jammy1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../libpython3.12-stdlib_3.12.8-1+jammy1_amd64.deb ...
Unpacking libpython3.12-stdlib:amd64 (3.12.8-1+jammy1) over (3.12.7-1+jammy1) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.12-stdlib_3.12.8-1+jammy1_amd64.deb (--unpack):
trying to overwrite '/etc/python3.12/sitecustomize.py', which is also in package libpython3.12-minimal:amd64 3.12.7-1+jammy1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/python3.12_3.12.8-1+jammy1_amd64.deb
/var/cache/apt/archives/libpython3.12-stdlib_3.12.8-1+jammy1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

What is best practice ?

Thanks

artnoise
  • 177

6 Answers6

45

Just ran into this myself. Looks like deadsnakes made some package changes, and the transition doesn't go over smoothly.

When you run apt --fix-broken install, you should see something like:

The following packages were automatically installed and are no longer required:
  libpython3.12-minimal python3.12-minimal

Run dpkg --force-depends -r libpython3.12-minimal python3.12-minimal to forcefully remove those packages. Then apt --fix-broken install should work to install the replacement packages, ie:

The following additional packages will be installed:
  libpython3.12-stdlib python3.12
ziddey
  • 551
15

I removed all the python3.12 packages, then reinstall. It worked for me.

sudo apt list --installed | grep 'python3.12' | cut -d'/' -f1 | xargs -o sudo apt autoremove && sudo apt install python3.12-full
Nico
  • 151
5

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.
Gergely M
  • 151
0

Ok with :

comment line # /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-jammy.list.
 apt --fix-broken install

enable repos deadsnakes. $ 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 update && sudo apt upgrade $ sudo apt install python3.12-dev $ sudo apt full-upgrade python3.12 $ sudo apt install python3.12-venv

thanks 4 help.

artnoise
  • 177
0

For Ubuntu 24.04 and other systems, which have python 3.12 also as main system package, don't use the answer from ziddey, because you will break the system...

If you have installed python from deadsnake repository, purge just this repository: sudo apt update sudo apt install ppa-purge sudo ppa-purge ppa:deadsnakes/ppa

This worked for me on Mint 22 (ubuntu 24.04 based).

Daniel
  • 1
-1

The issue arises because the python3.12 and python3.12-minimal packages both contain the file /usr/bin/python3.12, and dpkg is unable to handle this conflict automatically.

To solve this you can remove python3.12-minimal and install python3.12

sudo apt-get remove python3.12-minimal
sudo apt-get install python3.12

Finally you should check if all conflicts are solved.

sudo apt-get clean
sudo apt-get update
sudo apt-get upgrade