fix pip module resolution (#78000) (#78005)

* `importlib.util` appears to be lazily imported and is sometimes unavailable as an attribute of `importlib` without an explicit import

(cherry picked from commit 6e78425f8d)
pull/78023/head
Matt Davis 4 years ago committed by GitHub
parent 2cc9333e97
commit 482ce8fa8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- pip - fix cases where resolution of pip Python module fails when importlib.util has not already been imported

@ -455,15 +455,15 @@ def _get_pip(module, env=None, executable=None):
def _have_pip_module(): # type: () -> bool
"""Return True if the `pip` module can be found using the current Python interpreter, otherwise return False."""
try:
import importlib
from importlib.util import find_spec
except ImportError:
importlib = None
find_spec = None # type: ignore[assignment] # type: ignore[no-redef]
if importlib:
if find_spec:
# noinspection PyBroadException
try:
# noinspection PyUnresolvedReferences
found = bool(importlib.util.find_spec('pip'))
found = bool(find_spec('pip'))
except Exception:
found = False
else:

Loading…
Cancel
Save