From 04f2091c4f4d1db4c801f99f8744d7521d11315d Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Sun, 24 Jul 2022 12:42:54 +0100 Subject: [PATCH] Remove the setuptools-provided distutils hack, if using distutils This ensures that pip's imported copy of distutils comes from the standard library, if/when the hack needs to be used. --- src/pip/_internal/locations/_distutils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pip/_internal/locations/_distutils.py b/src/pip/_internal/locations/_distutils.py index aac821888d5..0a734bf9b76 100644 --- a/src/pip/_internal/locations/_distutils.py +++ b/src/pip/_internal/locations/_distutils.py @@ -3,6 +3,14 @@ # The following comment should be removed at some point in the future. # mypy: strict-optional=False +# If pip's going to use distutils, it should not be using the copy that setuptools +# might have injected into the environment. The least-worst option for ensuring this +# seems to be to try to remove the injected shim, if it's injected. +try: + __import__("_distutils_hack").remove_shim() +except ImportError: + pass + import logging import os import sys