Trouble bundling python with classic confinement in core20/4.0.4

Hello, I’m back here in 2024, updating for the core24 app. I’ve changed the snapcraft.yaml syntax to the newer versions and updated the list of packages to stage, and now we build perfectly well, and run on the machine it was built on, but don’t run when moving the snap to another (earlier) ubuntu machine. This makes me think that the packages are once again not getting staged/linked/patched properly, along with the snapcraft linter saying that libpython3.12.so.1.0 is unused.

The error I get when running on another machine is Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding, which seems to usually be a PYTHONPATH/PYTHONHOME issue, but that doesn’t quite make sense here. Looking at the variables the error spits out, on a working (older) version, when running /snap/certbot/current/bin/python3, sys.prefix is /snap/certbot/current, but on the updated version it’s now /usr; same with exec_prefix. And sys.path is similarly pointing to the /usr/lib pythons instead of inside the snap as well. So maybe this is a problem with patching somehow? I have now added build-attributes: enable-patchelf to the snapcraft.yaml, but did the actual patching get changed instead of just defaulting to no patching? Anything else I’m missing here? I’ve scoured the documentation but have run out of things to try.

All changes can be seen in this PR: Update python version in snaps by ohemorange · Pull Request #9956 · certbot/certbot · GitHub

Edit: this looks related snapcraft `8.0.2`+ python plugin classic core22 snap ModuleNotFoundError · Issue #4615 · canonical/snapcraft · GitHub

Edit 2: since I can’t change the topic title, I’m making a new one.