Reputation: 21
I'm trying to change the location of site-packages on a per interpreter basis, much like venv does to override site-packages.
a) using sitecustomize.py - this doesn't work because sitecustomize.py is imported by site.py (pystdlib module), and site.py goes ahead and adds the system site-packages. I'm not aware of a way to undo this.
b) starting python with the -S flag (which disables site.py), but this also disables sitecustomize.py, leaving no site-packages at all, which would be desirable, except I can't find a way to inject my own version of site.py or run sitecustomize.py with this flag set, or for that matter inject any bootstrap code on interpreter startup without using sitecustomize.py.
c) modifying site.py for the whole python installation, but this does nothing as the module is frozen and imported from somewhere else (see here: https://github.com/python/cpython/issues/107344 they have a similar unresolved issue)
There doesn't appear to be (at least a documented) way to do this beyond forking my own version of python, which is rather extreme for what is a seemingly simple problem.
site.py docs: https://docs.python.org/3/library/site.html
Upvotes: 0
Views: 398