diff --git a/news/6543.bugfix b/news/6543.bugfix new file mode 100644 index 00000000000..6c06999c4f3 --- /dev/null +++ b/news/6543.bugfix @@ -0,0 +1 @@ +Work around failure to import ctypes when resolving glibc version string. \ No newline at end of file diff --git a/src/pip/_internal/utils/glibc.py b/src/pip/_internal/utils/glibc.py index 5bea655ebcc..256552a42b2 100644 --- a/src/pip/_internal/utils/glibc.py +++ b/src/pip/_internal/utils/glibc.py @@ -1,11 +1,16 @@ from __future__ import absolute_import -import ctypes import re import warnings from pip._internal.utils.typing import MYPY_CHECK_RUNNING +# Work around https://bugs.python.org/issue37060. +try: + import ctypes +except (ImportError, OSError): + ctypes = None + if MYPY_CHECK_RUNNING: from typing import Optional, Tuple @@ -14,6 +19,9 @@ def glibc_version_string(): # type: () -> Optional[str] "Returns glibc version string, or None if not using glibc." + if not ctypes: + return None + # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen # manpage says, "If filename is NULL, then the returned handle is for the # main program". This way we can let the linker do the work to figure out