9

I tried to install python3.12 from here. Then I wanted to switch the default python3 (3.10) to the newly installed and delete the old (3.10) one but it turns out, I can't get rid of the old version easily as I thought. No matter what I do, it takes all the system files with it. I once messed up my Ubuntu 16.04 like this and I don't wanna do that again.
Moving on, after I changed the python3 to run python3.12 using update-alternatives command, the apt stopped working and a lot of errors occurred.
This error occurred in addition to the below error when I changed the python3 version:

Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 29, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

This error occur whenever I run apt:

Setting up libpython3.12-testsuite (3.12.1-1+jammy1) ...
  File "/usr/lib/python3.12/test/test_future_stmt/badsyntax_future10.py", line 3
    from __future__ import print_function
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from __future__ imports must occur at the beginning of the file
dpkg: error processing package libpython3.12-testsuite (--configure):
 installed libpython3.12-testsuite package post-installation script subprocess r
eturned error exit status 1
Setting up idle-python3.12 (3.12.1-1+jammy1) ...
Setting up python3.12-venv (3.12.1-1+jammy1) ...
dpkg: dependency problems prevent configuration of python3.12-full:
 python3.12-full depends on libpython3.12-testsuite; however:
  Package libpython3.12-testsuite is not configured yet.

dpkg: error processing package python3.12-full (--configure): dependency problems - leaving unconfigured No apport report written because the error message indicates its a followup erro r from a previous failure. Setting up python3.12-gdbm:amd64 (3.12.1-1+jammy1) ... Processing triggers for mailcap (3.70+nmu1ubuntu1) ... Processing triggers for desktop-file-utils (0.26-1ubuntu3) ... Processing triggers for gnome-menus (3.36.0-1ubuntu3) ... Processing triggers for man-db (2.10.2-1) ... Errors were encountered while processing: libpython3.12-testsuite python3.12-full E: Sub-process /usr/bin/dpkg returned an error code (1)

When I restarted it, the terminal won't open at all. I had to use Ctrl+Alt+F3 to get a tty and change the python3 version.
Now, I've completely removed python3.12 and I'm waiting for a response.

1 Answers1

13

First

Never delete or replace the official Python version installed in Ubuntu Linux! It's a mistake of the author of the article you followed, that you can remove unneeded versions of Python after installing Python 3.12. You could never remove the official one. For Ubuntu 22.04 it's 3.10.

In your situation, I don't believe you already deleted the official Python 3.10. You have just removed it from python or python3 alternatives by the update-alternatives program. You can restore APT to a working state again just by running a set of commands like:

  • sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10
  • sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10

Or similar. I hope you will get the docs of update-alternatives and find out the way how to restore your 3.10 Python version in the list of alternatives.

You still can have a few versions installed, along with the official one, and added them all to the alternatives. This will allow your IDEs and other software to see and choose which version to use.

Second

The problem with not installing Python 3.12 fully is because of the incorrectly updated Python package (3.12.1) by the authors of the source repository - deadsnakes. They need to rebuild it with the resolution in order to the core policies which make it unable to be installed (SyntaxError: from __future__ imports must occur at the beginning of the file). I don't see any other ways except the 2 following:

  • wait for the resolution by repo authors
  • raise this issue with them via official communication ways

As an example, raising this issue can be done on their main issue tracker on GitHub. After they fix the package, you will be able to just run sudo apt update && sudo apt upgrade to get the newest Python 3.12.1 updated fully.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
dilnix
  • 146
  • For Ruby, there is a great page explaining why you should not use the system Ruby: https://dontusesystemruby.com/. I am sure a similar site exists for Python as well. But even if it doesn't, most of that site also applies to Python. While the specific software packages mentioned on the site obviously are not relevant, all the arguments and point made apply equally to Python, PHP, Perl, etc. – Jörg W Mittag Dec 09 '23 at 22:19
  • 1
    @JörgWMittag, on Linux you can install multiple versions of Python, and use whatever you want. The system one is pre-built and installed by OS provider just because they need to base some system utils on it. It's not only about Ubuntu. I'm using, for example, Fedora too, and there, if you remove the alternative setting for a system Python version, its package manager dnf stops working too. It's just a wide dependency, but it doesn't stop you from installing and using of almost any other version. With Ruby, there is a similar situation, but not the same. – dilnix Dec 09 '23 at 22:30
  • 1
    Not exactly what I was looking for but thanks for the knowledge. – Normal Dude Dec 11 '23 at 06:36