By default a directory like %APPDATA%\Python\Python311\site-packages (Windows) or ~/.local/lib/python311/site-packages (Unix) is added to the sys.path on startup, if it exists.
This can be suppressed by passing -s on the command line or setting PYTHONNOUSERSITE in the environment.
With embedded Python, there are circumstances where a location entirely controlled by the user is particularly unwanted, so we want to go down the NOUSERSITE route. However the command line is not available, and it also may not be possible to change the environment of the running process when we come to initialize Python.
My question then is how to ensure that NOUSERSITE is respected when using something like Py_InitializeEx and similar configuration API functions. I did find Issue 35706: Make it easier to use a venv with an embedded Python interpreter - Python tracker which is clearly related, but don’t see a prescribed way to do things. Should I be aiming to use Py_SetPath with everything except the user-specific path?
Thank you.