From 5deb416b8edf479757199d6774ed5f9df94d264a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 23 Aug 2021 14:30:09 +0200 Subject: [PATCH 1/2] Add `install=True` argument to `check_requirements` --- utils/general.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/utils/general.py b/utils/general.py index 0b6e8fc7fb9a..79334c50afa0 100755 --- a/utils/general.py +++ b/utils/general.py @@ -172,7 +172,7 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals @try_except -def check_requirements(requirements='requirements.txt', exclude=()): +def check_requirements(requirements='requirements.txt', exclude=(), install=True): # Check installed dependencies meet requirements (pass *.txt file or list of packages) prefix = colorstr('red', 'bold', 'requirements:') check_python() # check python version @@ -188,13 +188,17 @@ def check_requirements(requirements='requirements.txt', exclude=()): try: pkg.require(r) except Exception as e: # DistributionNotFound or VersionConflict if requirements not met - 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}') + s = f"{prefix} {r} not found and is required by YOLOv5" + if install: + print(f"{s}, 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}') + else: + print(f'{s}') if n: # if packages updated source = file.resolve() if 'file' in locals() else requirements From 484ae446934bc51d969053de750ed162ea37a7f6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 23 Aug 2021 14:38:04 +0200 Subject: [PATCH 2/2] Update general.py --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 79334c50afa0..16244903575a 100755 --- a/utils/general.py +++ b/utils/general.py @@ -198,7 +198,7 @@ def check_requirements(requirements='requirements.txt', exclude=(), install=True except Exception as e: print(f'{prefix} {e}') else: - print(f'{s}') + print(f'{s}. Please install and rerun your command.') if n: # if packages updated source = file.resolve() if 'file' in locals() else requirements