From 19e802250e93ee5c9b35ef72a70d0ae4e32155c4 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Tue, 15 Nov 2022 09:46:55 +0100 Subject: [PATCH] Use the "venv" scheme if available to obtain prefixed lib paths get_prefixed_libs() computes the Python path for libraries in a pip isolation environment. Python 3.11 introduced the "venv" path scheme to be used in these cases. Use it if available. This solves a bug on Homebrew's Python 3.10 and later where the default paths scheme when Python is invoked outside a virtual environment is "osx_framework_library" and does not relative to the "{base}" or "{platbase}" variables. Fixes #11539. --- news/11598.bugfix.rst | 1 + src/pip/_internal/locations/_sysconfig.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 news/11598.bugfix.rst diff --git a/news/11598.bugfix.rst b/news/11598.bugfix.rst new file mode 100644 index 00000000000..031ff9ddca0 --- /dev/null +++ b/news/11598.bugfix.rst @@ -0,0 +1 @@ +Use the "venv" scheme if available to obtain prefixed lib paths. diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index 0bbc9283db7..5c870c783b3 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -214,5 +214,9 @@ def get_platlib() -> str: def get_prefixed_libs(prefix: str) -> typing.Tuple[str, str]: - paths = sysconfig.get_paths(vars={"base": prefix, "platbase": prefix}) + vars = {"base": prefix, "platbase": prefix} + if "venv" in sysconfig.get_scheme_names(): + paths = sysconfig.get_paths(vars=vars, scheme="venv") + else: + paths = sysconfig.get_paths(vars=vars) return (paths["purelib"], paths["platlib"])