Certbot not running with python 3.12

Hey,

i am running Dietpi on my RPi 400 with Teslamate, Unbound, Adguard Home, Home Assistant and other stuff.

Managed to update Python to 3.12 as Home Assistant and other software will need it in short future.
Unfortunately, Certbot (installed using diet pi-software) no longer works. I have already uninstalled and reinstalled it using the Dietpi-software. But nothing happens.

Here is the log entry. Does anyone have any ideas? My knowledge is rudimentary, but I’m finding my way around as far as I can.

DietPi-LetsEncrypt
─────────────────────────────────────────────────────
 Mode: Running Certbot

[ INFO ] DietPi-LetsEncrypt | No webserver detected, running Certbot in standalone mode
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/importlib/metadata/__init__.py", line 397, in from_name
    return next(cls.discover(name=name))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/certbot", line 33, in <module>
    sys.exit(load_entry_point('certbot==1.12.0', 'console_scripts', 'certbot')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/certbot", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/metadata/__init__.py", line 861, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/metadata/__init__.py", line 399, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for certbot
[FAILED] DietPi-LetsEncrypt | Certbot failed, please check its above terminal output. Aborting...

I have searched the existing open and closed issues

Required Information

  • DietPi version | cat /boot/dietpi/.version
    G_DIETPI_VERSION_CORE=9
    G_DIETPI_VERSION_SUB=0
    G_DIETPI_VERSION_RC=2
    G_GITBRANCH=β€˜master’
    G_GITOWNER=β€˜MichaIng’

  • Distro version | bullseye 0

  • Kernel version | Linux DietPi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux

  • Architecture | arm64

  • SBC model | RPi 400

  • Power supply used | standard version from bundle

  • SD card used | SSD ist mounted

Additional Information (if applicable)

  • Software title | certbot

Expected behaviour

  • certbot should renew my crt files, used for example in Adguard Home

Actual behaviour

  • Certbot fails

Extra details

  • …

HA has an own PyEnv and is not using the python version you updated now. Probably this broke certbot. If possible restore your system.

Following might be interesting for you Home Assistant requires Python 3.12 Β· Issue #6906 Β· MichaIng/DietPi Β· GitHub

Ah, would have been nice to know before.

As I updated Home Assistant to 2024.2.1 today, the warning about Python 3.12 disappeared.

No other option to fix Certbot 1.12.0 to run ion Python 3.12?

Was also a bit confused as I found out that there seems to be another β€œversion” out there. (GitHub - certbot/certbot: Certbot is EFF's tool to obtain certs from Let's Encrypt and (optionally) auto-enable HTTPS on your server. It can also act as a client for any other CA that uses the ACME protocol.) which has Version 2.9.0 and a new Python 3.12 support.
But it seems not possible to use it on dietpi for now.

If you want to run Certbot on Python 3.12, it needs to be built against Python 3.12. The Debian packages are logically built against the Python version shipped by Debian, 3.11 on Bookworm. Since Python 3.12 on system level can break a lot more, I strongly recommend to restore a backup or undo/remove the custom Python installation.

hmm, okay. That is definitely not my skill level. Thanks for helping. Adguard is now without crt. But working. It is what it is.

You don’t have a backup to restore? You already tried to remove Python 3.12?

No Backup to be honest as it did not seem complicated. I was following instructions from a website (which I forgot) and installed python 3.12 compiled from source. took around one hour. after that I remember that the instructions said there are now 2 versions installed and that I have to β€œlink” anything on the 3.12 version.

did a research how to β€œunlink” but did not found out what to do / what I did…

Sorry, I am interested but no coding nerd. everything is learning by doing and instructions from websites. I am proud as hell to have a RPi 400 runing will all that stuff working for more then a.year xD

Lesson for today, always create a backup before playing with the configuration

True :confused:

Found the page with the instructions.

I guess my problem is the part of β€œmake Python 3.12 the default version”.
Any chances to change commands that the older version is used?

When installing software compiled from source, it is usually installed to /usr/local sub directories, from where you can simply rm it. Uhh, the guide does some nonsense, overwriting the Python executables from /usr/bin with symlinks to /usr/local/bin. This does not only break package consistency and is probably reverted automatically on next Python package upgrade. It is also unnecessary, as binaries in /usr/local/bin and libraries in /usr/local/lib are always prioritised anyway.

Try this:

rm -R /usr/local/lib/python3.12 /usr/local/bin/python* /usr/bin/python{,3}
ln -s python3.9 /usr/bin/python3

This should fix Certbot. To check for other files to cleanup:

ls -l /usr/local/{,bin,lib}
1 Like

Thank you so much. That is the solution! Feel free to send me a DM with your PayPal. I owe you a coffee or beer!

do you need the output from the cleanup command to check for other files?

1 Like

This will reach @MichaIng directly :smiley:

1 Like

Feel free to post it, so we probably find some more remains of the Python 3.12 installation.

/usr/local/:
total 32
drwxr-xr-x 2 root root 4096 Feb 14 21:03 bin
drwxr-xr-x 2 root root 4096 May  2  2022 etc
drwxr-xr-x 2 root root 4096 May  2  2022 games
drwxr-xr-x 3 root root 4096 Feb  8 18:34 include
drwxr-xr-x 4 root root 4096 Feb 14 21:03 lib
lrwxrwxrwx 1 root root    9 May  2  2022 man -> share/man
drwxr-xr-x 2 root root 4096 May  2  2022 sbin
drwxr-xr-x 4 root root 4096 May  2  2022 share
drwxr-xr-x 3 root root 4096 May 25  2022 src

/usr/local/bin:
total 58336
-rwxr-xr-x 1 root root      102 Feb  8 18:34 2to3-3.12
-rwxr-xr-x 1 root root 59695142 Feb  9 21:08 docker-compose
-rwxr-xr-x 1 root root      100 Feb  8 18:34 idle3.12
-rwxr-xr-x 1 root root      211 Feb 11 16:33 jws
-rwxr-xr-x 1 root root      221 Feb 11 16:33 pip
-rwxr-xr-x 1 root root      221 Feb 11 16:33 pip3
-rwxr-xr-x 1 root root      221 Feb 11 16:33 pip3.12
-rwxr-xr-x 1 root root      221 Feb  7 20:08 pip3.9
lrwxrwxrwx 1 root root       47 May 25  2022 pivpn -> /usr/local/src/pivpn/scripts/wireguard/pivpn.sh
-rwxr-xr-x 1 root root       85 Feb  8 18:34 pydoc3.12
-rwxr-xr-x 1 root root      208 Dec  8 18:05 wheel

/usr/local/lib:
total 73708
-rwxr-xr-x 1 root root 75463610 Feb  8 17:55 libpython3.12.a
drwxr-xr-x 2 root root     4096 Feb  8 18:34 pkgconfig
drwxr-xr-x 3 root root     4096 May 25  2022 python3.9
root@DietPi:~# 

Btw, if you still have the Python 3.12 source directory, from where you installed it, you can use the following command to list all files which were/would be installed, respectively the commands done for the installation:

sudo make -n altinstall

The following ones are definitely from Python 3.12 and can be removed:

sudo rm /usr/local/bin/{2to3-,idle,pip,pydoc}3.12
sudo rm /usr/local/lib/libpython3.12.a

There are some below /usr/local/man, /usr/local/include and probably /usr/local/share as well.

/usr/local/bin/pip and pip3 there are from the Python 3.12 installation as well, according to their modification date. But AFAIK they are identical to the pip3.9 one, as all pip does is invoking python3 -m pip and passing through the arguments, i.e. it should not be version-specific. But you can test this:

pip3 --version

Thank you so far :blush:

root@DietPi:~# pip3 --version
pip 24.0 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)

So should be fine. I Also removed the ones that definitely are from Python 3.12.

The source directory was deleted after install.

1 Like