Skip to content

Commit dd18001

Browse files
authored
bpo-41627: Distinguish 32 and 64-bit user site packages on Windows (GH-22098)
Also fixes the error message returned when sysconfig fails to interpolate a variable correctly.
1 parent 51b84f8 commit dd18001

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Lib/site.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ def _get_path(userbase):
274274
version = sys.version_info
275275

276276
if os.name == 'nt':
277-
return f'{userbase}\\Python{version[0]}{version[1]}\\site-packages'
277+
ver_nodot = sys.winver.replace('.', '')
278+
return f'{userbase}\\Python{ver_nodot}\\site-packages'
278279

279280
if sys.platform == 'darwin' and sys._framework:
280281
return f'{userbase}/lib/python/site-packages'

Lib/sysconfig.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
},
5454
# NOTE: When modifying "purelib" scheme, update site._get_path() too.
5555
'nt_user': {
56-
'stdlib': '{userbase}/Python{py_version_nodot}',
57-
'platstdlib': '{userbase}/Python{py_version_nodot}',
58-
'purelib': '{userbase}/Python{py_version_nodot}/site-packages',
59-
'platlib': '{userbase}/Python{py_version_nodot}/site-packages',
60-
'include': '{userbase}/Python{py_version_nodot}/Include',
61-
'scripts': '{userbase}/Python{py_version_nodot}/Scripts',
56+
'stdlib': '{userbase}/Python{py_version_nodot_plat}',
57+
'platstdlib': '{userbase}/Python{py_version_nodot_plat}',
58+
'purelib': '{userbase}/Python{py_version_nodot_plat}/site-packages',
59+
'platlib': '{userbase}/Python{py_version_nodot_plat}/site-packages',
60+
'include': '{userbase}/Python{py_version_nodot_plat}/Include',
61+
'scripts': '{userbase}/Python{py_version_nodot_plat}/Scripts',
6262
'data': '{userbase}',
6363
},
6464
'posix_user': {
@@ -149,10 +149,10 @@ def is_python_build(check_home=False):
149149
def _subst_vars(s, local_vars):
150150
try:
151151
return s.format(**local_vars)
152-
except KeyError:
152+
except KeyError as var:
153153
try:
154154
return s.format(**os.environ)
155-
except KeyError as var:
155+
except KeyError:
156156
raise AttributeError('{%s}' % var) from None
157157

158158
def _extend_dict(target_dict, other_dict):
@@ -431,6 +431,7 @@ def _init_non_posix(vars):
431431
vars['EXE'] = '.exe'
432432
vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
433433
vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
434+
vars['TZPATH'] = ''
434435

435436
#
436437
# public APIs
@@ -543,10 +544,13 @@ def get_config_vars(*args):
543544
except AttributeError:
544545
# sys.abiflags may not be defined on all platforms.
545546
_CONFIG_VARS['abiflags'] = ''
547+
try:
548+
_CONFIG_VARS['py_version_nodot_plat'] = sys.winver.replace('.', '')
549+
except AttributeError:
550+
_CONFIG_VARS['py_version_nodot_plat'] = ''
546551

547552
if os.name == 'nt':
548553
_init_non_posix(_CONFIG_VARS)
549-
_CONFIG_VARS['TZPATH'] = ''
550554
if os.name == 'posix':
551555
_init_posix(_CONFIG_VARS)
552556
# For backward compatibility, see issue19555
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The user site directory for 32-bit now includes a ``-32`` suffix to
2+
distinguish it from the 64-bit interpreter's directory.

0 commit comments

Comments
 (0)