-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sysconfig
data inconsistencies caused by the disabling the site
initialization on virtual environments
#126789
Comments
Things are a bit messy, as the virtual environment mechanism is technically part of the Anyway, to match this model, if $ python -S
Python 3.14.0a1+ experimental free-threading build (heads/main:de0d5c6e2e1, Oct 23 2024, 15:37:46) [GCC 14.2.1 20240910] on linux
>>> import sysconfig
>>> 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'}
>>> import site
>>> site.main()
>>> 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'} |
Correction: |
Signed-off-by: Filipe Laíns <lains@riseup.net>
sysconfig.get_paths()
inconsistencies caused by the disabling the site
initialization on virtual environmentssysconfig
data inconsistencies caused by the disabling the site
initialization on virtual environments
While fixing the main bug, I have noticed that the IMO this is worth to fix, but we probably shouldn't backport it as it is a significant behavior change, and there's a possibility it would break existing user code. |
Just some more background on this, |
(cherry picked from commit acbd5c9) Co-authored-by: Filipe Laíns 🇵🇸 <lains@riseup.net>
(cherry picked from commit acbd5c9) Co-authored-by: Filipe Laíns 🇵🇸 <lains@riseup.net>
Co-authored-by: Filipe Laíns 🇵🇸 <lains@riseup.net>
Co-authored-by: Filipe Laíns 🇵🇸 <lains@riseup.net>
…d. (pythonGH-126941) (cherry picked from commit 3938fd6)
macOS: 3.14.0a1Hmm, I can't reproduce this in macOS with the first 3.14 alpha. I get the same paths in all cases: ❯ python3.14 -S
Python 3.14.0a1 (v3.14.0a1:8cdaca8b25e, Oct 15 2024, 15:51:57) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'platstdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'purelib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'platlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'include': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'platinclude': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'scripts': '/Library/Frameworks/Python.framework/Versions/3.14/bin', 'data': '/Library/Frameworks/Python.framework/Versions/3.14'}
>>> import site
>>> site.main()
>>> sysconfig.get_paths()
{'stdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'platstdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'purelib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'platlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'include': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'platinclude': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'scripts': '/Library/Frameworks/Python.framework/Versions/3.14/bin', 'data': '/Library/Frameworks/Python.framework/Versions/3.14'} ❯ python3.14
Python 3.14.0a1 (v3.14.0a1:8cdaca8b25e, Oct 15 2024, 15:51:57) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'platstdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'purelib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'platlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'include': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'platinclude': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'scripts': '/Library/Frameworks/Python.framework/Versions/3.14/bin', 'data': '/Library/Frameworks/Python.framework/Versions/3.14'} ❯ python3.14 -S
Python 3.14.0a1 (v3.14.0a1:8cdaca8b25e, Oct 15 2024, 15:51:57) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
>>> import site
>>> site.main()
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'platstdlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14', 'purelib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'platlib': '/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages', 'include': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'platinclude': '/Library/Frameworks/Python.framework/Versions/3.14/include/python3.14', 'scripts': '/Library/Frameworks/Python.framework/Versions/3.14/bin', 'data': '/Library/Frameworks/Python.framework/Versions/3.14'} Debian: 3.14.0a1Similarly when testing the first alpha on Linux using Docker: ❯ docker run -it python:3.14.0a1 /bin/bash
root@85391c98ea86:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/" root@85391c98ea86:/# python -S
Python 3.14.0a1 (main, Nov 13 2024, 14:15:00) [GCC 12.2.0] on linux
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14', 'platstdlib': '/usr/local/lib/python3.14', 'purelib': '/usr/local/lib/python3.14/site-packages', 'platlib': '/usr/local/lib/python3.14/site-packages', 'include': '/usr/local/include/python3.14', 'platinclude': '/usr/local/include/python3.14', 'scripts': '/usr/local/bin', 'data': '/usr/local'}
>>> import site
>>> site.main()
>>> sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14', 'platstdlib': '/usr/local/lib/python3.14', 'purelib': '/usr/local/lib/python3.14/site-packages', 'platlib': '/usr/local/lib/python3.14/site-packages', 'include': '/usr/local/include/python3.14', 'platinclude': '/usr/local/include/python3.14', 'scripts': '/usr/local/bin', 'data': '/usr/local'} root@85391c98ea86:/# python
Python 3.14.0a1 (main, Nov 13 2024, 14:15:00) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14', 'platstdlib': '/usr/local/lib/python3.14', 'purelib': '/usr/local/lib/python3.14/site-packages', 'platlib': '/usr/local/lib/python3.14/site-packages', 'include': '/usr/local/include/python3.14', 'platinclude': '/usr/local/include/python3.14', 'scripts': '/usr/local/bin', 'data': '/usr/local'} Python 3.14.0a1 (main, Nov 13 2024, 14:15:00) [GCC 12.2.0] on linux
>>> import site
>>> site.main()
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/usr/local/lib/python3.14', 'platstdlib': '/usr/local/lib/python3.14', 'purelib': '/usr/local/lib/python3.14/site-packages', 'platlib': '/usr/local/lib/python3.14/site-packages', 'include': '/usr/local/include/python3.14', 'platinclude': '/usr/local/include/python3.14', 'scripts': '/usr/local/bin', 'data': '/usr/local'} macOS:
|
… Android. (pythonGH-126941) (cherry picked from commit 3938fd6)
… Android. (pythonGH-126941) (cherry picked from commit 3938fd6) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
…izations" This reverts commit acbd5c9. Signed-off-by: Filipe Laíns <lains@riseup.net>
…initializations" Signed-off-by: Filipe Laíns <lains@riseup.net>
@hugovk, sorry I just say this now. I should have mentioned it in the issue text, but as per the title this only affects virtual environments. The issue is that currently I hope that helps clarify things. Let me know if you have any more questions. |
Thanks for the clarification! |
Bug report
Bug description:
Currently, running the Python interpreter with
-S
(disabling thesite
module initialization) causes several inconsistenciessysconfig.get_paths()
depends on whethersysconfig
was imported before or after thesite
initializationCurrently,
sysconfig
calculates the paths at import time and caches them. This results in it resulting incorrect paths if thesite
initialization happens aftersysconfig
was imported.Expected output when the
site
module has been initialized:And just to make sure this is not dependent on the interpreter being run with
-S
, and rather on thesysconfig
import time.CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: