@@ -173,9 +173,7 @@ def joinuser(*args):
173
173
_PY_VERSION = sys .version .split ()[0 ]
174
174
_PY_VERSION_SHORT = f'{ sys .version_info [0 ]} .{ sys .version_info [1 ]} '
175
175
_PY_VERSION_SHORT_NO_DOT = f'{ sys .version_info [0 ]} { sys .version_info [1 ]} '
176
- _PREFIX = os .path .normpath (sys .prefix )
177
176
_BASE_PREFIX = os .path .normpath (sys .base_prefix )
178
- _EXEC_PREFIX = os .path .normpath (sys .exec_prefix )
179
177
_BASE_EXEC_PREFIX = os .path .normpath (sys .base_exec_prefix )
180
178
# Mutex guarding initialization of _CONFIG_VARS.
181
179
_CONFIG_VARS_LOCK = threading .RLock ()
@@ -466,8 +464,10 @@ def _init_config_vars():
466
464
# Normalized versions of prefix and exec_prefix are handy to have;
467
465
# in fact, these are the standard versions used most places in the
468
466
# Distutils.
469
- _CONFIG_VARS ['prefix' ] = _PREFIX
470
- _CONFIG_VARS ['exec_prefix' ] = _EXEC_PREFIX
467
+ _PREFIX = os .path .normpath (sys .prefix )
468
+ _EXEC_PREFIX = os .path .normpath (sys .exec_prefix )
469
+ _CONFIG_VARS ['prefix' ] = _PREFIX # FIXME: This gets overwriten by _init_posix.
470
+ _CONFIG_VARS ['exec_prefix' ] = _EXEC_PREFIX # FIXME: This gets overwriten by _init_posix.
471
471
_CONFIG_VARS ['py_version' ] = _PY_VERSION
472
472
_CONFIG_VARS ['py_version_short' ] = _PY_VERSION_SHORT
473
473
_CONFIG_VARS ['py_version_nodot' ] = _PY_VERSION_SHORT_NO_DOT
@@ -540,6 +540,7 @@ def get_config_vars(*args):
540
540
With arguments, return a list of values that result from looking up
541
541
each argument in the configuration variable dictionary.
542
542
"""
543
+ global _CONFIG_VARS_INITIALIZED
543
544
544
545
# Avoid claiming the lock once initialization is complete.
545
546
if not _CONFIG_VARS_INITIALIZED :
@@ -550,6 +551,15 @@ def get_config_vars(*args):
550
551
# don't re-enter init_config_vars().
551
552
if _CONFIG_VARS is None :
552
553
_init_config_vars ()
554
+ else :
555
+ # If the site module initialization happened after _CONFIG_VARS was
556
+ # initialized, a virtual environment might have been activated, resulting in
557
+ # variables like sys.prefix changing their value, so we need to re-init the
558
+ # config vars (see GH-126789).
559
+ with _CONFIG_VARS_LOCK :
560
+ if _CONFIG_VARS ['base' ] != os .path .normpath (sys .prefix ):
561
+ _CONFIG_VARS_INITIALIZED = False
562
+ _init_config_vars ()
553
563
554
564
if args :
555
565
vals = []
0 commit comments