From 67cf126cf840eead9fc396ceed0ea17c5ac0985a Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 10 Dec 2024 19:16:33 +0000 Subject: [PATCH] Disable PIP version check in collect_env (#142308) Disables version check which might require users to reach out to PyPI, reference: https://pip.pypa.io/en/latest/cli/pip/#cmdoption-disable-pip-version-check Switches pip to be used directly as a python module (`python3 -mpip`) instead of relying on `pip3` or `pip` Pull Request resolved: https://github.com/pytorch/pytorch/pull/142308 Approved by: https://github.com/seemethere --- torch/utils/collect_env.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/torch/utils/collect_env.py b/torch/utils/collect_env.py index 3cba71da0df..ce397d6090e 100644 --- a/torch/utils/collect_env.py +++ b/torch/utils/collect_env.py @@ -439,20 +439,19 @@ def get_pip_packages(run_lambda, patterns=None): if patterns is None: patterns = PIP_PATTERNS + COMMON_PATTERNS + NVIDIA_PATTERNS - # People generally have `pip` as `pip` or `pip3` - # But here it is invoked as `python -mpip` - def run_with_pip(pip): - out = run_and_read_all(run_lambda, pip + ["list", "--format=freeze"]) - return "\n".join( - line - for line in out.splitlines() - if any(name in line for name in patterns) - ) - pip_version = 'pip3' if sys.version[0] == '3' else 'pip' - out = run_with_pip([sys.executable, '-mpip']) - return pip_version, out + os.environ['PIP_DISABLE_PIP_VERSION_CHECK'] = '1' + # People generally have pip as `pip` or `pip3` + # But here it is invoked as `python -mpip` + out = run_and_read_all(run_lambda, [sys.executable, '-mpip', 'list', '--format=freeze']) + filtered_out = '\n'.join( + line + for line in out.splitlines() + if any(name in line for name in patterns) + ) + + return pip_version, filtered_out def get_cachingallocator_config():