From 246967f32cfb9f3411caea6d1194b7407ae18c2c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 22 Jan 2025 16:48:09 +0100 Subject: [PATCH 1/2] gh-128779: Fix site venv() for system site-packages Add sys.base_exec_prefix to prefixes if pyvenv.cfg enables system site-packages. --- Lib/site.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/site.py b/Lib/site.py index 92bd1ccdadd924..86a37a4b5c4564 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -637,6 +637,8 @@ def venv(known_paths): # but that's ok; known_paths will prevent anything being added twice if system_site == "true": PREFIXES.insert(0, sys.prefix) + if sys.base_exec_prefix != sys.exec_prefix: + PREFIXES.append(sys.base_exec_prefix) else: PREFIXES = [sys.prefix] ENABLE_USER_SITE = False From ca98ad77d5f17977ee6b7b79c7b5020e158b8481 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 26 Jan 2025 12:14:22 +0100 Subject: [PATCH 2/2] Apply Filipe's suggestion --- Lib/site.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Lib/site.py b/Lib/site.py index 86a37a4b5c4564..9da8b6724e1cec 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -633,14 +633,9 @@ def venv(known_paths): # Doing this here ensures venv takes precedence over user-site addsitepackages(known_paths, [sys.prefix]) - # addsitepackages will process site_prefix again if its in PREFIXES, - # but that's ok; known_paths will prevent anything being added twice if system_site == "true": - PREFIXES.insert(0, sys.prefix) - if sys.base_exec_prefix != sys.exec_prefix: - PREFIXES.append(sys.base_exec_prefix) + PREFIXES += [sys.base_prefix, sys.base_exec_prefix] else: - PREFIXES = [sys.prefix] ENABLE_USER_SITE = False return known_paths