Bug report
Bug description:
Currently, running the Python interpreter with -S (disabling the site module initialization) causes several inconsistencies sysconfig.get_paths() depends on whether sysconfig was imported before or after the site initialization
Currently, sysconfig calculates the paths at import time and caches them. This results in it resulting incorrect paths if the site initialization happens after sysconfig was imported.
$ python-SPython3.14.0a1+experimentalfree-threadingbuild (heads/main:de0d5c6e2e1, Oct232024, 15:37:46) [GCC14.2.120240910] onlinux>>>importsysconfig>>>sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14t', 'platstdlib': '/usr/local/lib/python3.14t', 'purelib': '/usr/local/lib/python3.14t/site-packages', 'platlib': '/usr/local/lib/python3.14t/site-packages', 'include': '/usr/local/include/python3.14td', 'platinclude': '/usr/local/include/python3.14td', 'scripts': '/usr/local/bin', 'data': '/usr/local'}
>>>importsite>>>site.main()
>>>sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14t', 'platstdlib': '/usr/local/lib/python3.14t', 'purelib': '/usr/local/lib/python3.14t/site-packages', 'platlib': '/usr/local/lib/python3.14t/site-packages', 'include': '/usr/local/include/python3.14td', 'platinclude': '/usr/local/include/python3.14td', 'scripts': '/usr/local/bin', 'data': '/usr/local'}Expected output when the site module has been initialized:
$ pythonPython3.14.0a1+experimentalfree-threadingbuild (heads/main:de0d5c6e2e1, Oct232024, 15:37:46) [GCC14.2.120240910] onlinuxType"help", "copyright", "credits"or"license"formoreinformation.
>>>importsysconfig>>>sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14t', 'platstdlib': '/home/anubis/.virtualenvs/test-sysconfig-paths/lib/python3.14t', 'purelib': '/home/anubis/.virtualenvs/test-sysconfig-paths/lib/python3.14t/site-packages', 'platlib': '/home/anubis/.virtualenvs/test-sysconfig-paths/lib/python3.14t/site-packages', 'include': '/usr/local/include/python3.14td', 'platinclude': '/usr/local/include/python3.14td', 'scripts': '/home/anubis/.virtualenvs/test-sysconfig-paths/bin', 'data': '/home/anubis/.virtualenvs/test-sysconfig-paths'}And just to make sure this is not dependent on the interpreter being run with -S, and rather on the sysconfig import time.
$ python-SPython3.14.0a1+experimentalfree-threadingbuild (heads/main:de0d5c6e2e1, Oct232024, 15:37:46) [GCC14.2.120240910] onlinux>>>importsite>>>site.main()
>>>importsysconfig>>>sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14t', 'platstdlib': '/home/anubis/.virtualenvs/test-sysconfig-paths/lib/python3.14t', 'purelib': '/home/anubis/.virtualenvs/test-sysconfig-paths/lib/python3.14t/site-packages', 'platlib': '/home/anubis/.virtualenvs/test-sysconfig-paths/lib/python3.14t/site-packages', 'include': '/usr/local/include/python3.14td', 'platinclude': '/usr/local/include/python3.14td', 'scripts': '/home/anubis/.virtualenvs/test-sysconfig-paths/bin', 'data': '/home/anubis/.virtualenvs/test-sysconfig-paths'}CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
Currently, running the Python interpreter with
-S(disabling thesitemodule initialization) causes several inconsistenciessysconfig.get_paths()depends on whethersysconfigwas imported before or after thesiteinitializationCurrently,
sysconfigcalculates the paths at import time and caches them. This results in it resulting incorrect paths if thesiteinitialization happens aftersysconfigwas imported.Expected output when the
sitemodule has been initialized:And just to make sure this is not dependent on the interpreter being run with
-S, and rather on thesysconfigimport time.CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Linked PRs