This is still a major problem with Ubuntu 24.04 and python 3.12. I
realize this choice has been in ubuntu for years after looking at other
bug reports that were rejected. Sadly, this choice breaks projects that
use the standard sitecustomize machinery to initialize their python
environments and force them into really bad workarounds and hacks.

For anyone else stumbling into this, one workaround is to modify the
/etc/python3.12/sitecustomize.py file to have a block like this appended
to the file:

#############################################################################################
# support a virtualenv's sitecustomize file
import importlib.machinery, os, sys, types

initial_paths = sys.path[:]
for p in initial_paths:
    if p.startswith(sys.exec_prefix) and p.endswith("site-packages"):
        venv_sitecustomize = os.path.join(p, "sitecustomize.py")
        if os.path.exists(venv_sitecustomize):
            sfl = importlib.machinery.SourceFileLoader("sitecustomize", 
venv_sitecustomize)
            sfl.exec_module(types.ModuleType(sfl.name))
##############################################################################################


The suggestions in the descriptions are excellent and would allow the apport 
stuff to work and not impact serious python backend projects that never want to 
install or use the apport bug reporting features and need to be able to use 
sitecustomize in their virtual environments.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1971637

Title:
  sitecustomize.py not imported in a virtual environment

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python3.10/+bug/1971637/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to