From 1e18b06b9944dd5ba9b8bd8dce5fa11bfb3b62c5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 4 Jun 2021 21:34:36 +0200 Subject: [PATCH] Improved `check_requirements()` offline-handling (#3466) Improve robustness of `check_requirements()` function to offline environments (do not attempt pip installs when offline). --- utils/general.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index d9ee432dcae3..a12b0aafba0e 100755 --- a/utils/general.py +++ b/utils/general.py @@ -163,10 +163,11 @@ def check_requirements(requirements='requirements.txt', exclude=()): try: pkg.require(r) except Exception as e: # DistributionNotFound or VersionConflict if requirements not met - n += 1 print(f"{prefix} {r} not found and is required by YOLOv5, attempting auto-update...") try: + assert check_online(), f"'pip install {r}' skipped (offline)" print(check_output(f"pip install '{r}'", shell=True).decode()) + n += 1 except Exception as e: print(f'{prefix} {e}')