From 699182294f363c7859aba69d0430d2844327cf4f Mon Sep 17 00:00:00 2001 From: Joseph Kocherhans Date: Wed, 20 Apr 2022 10:04:15 -0700 Subject: [PATCH 1/2] Added a way to skip dependency auto-installation. Setting the environment variable `YOLOv5_AUTOINSTALL=False` will skip installing any missing dependencies as if the user had passed `install=False` to `check_requirements`. --- utils/general.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/general.py b/utils/general.py index cc37ad5fff62..0631e366248b 100755 --- a/utils/general.py +++ b/utils/general.py @@ -322,6 +322,8 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals @try_except def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True): # Check installed dependencies meet requirements (pass *.txt file or list of packages) + if os.environ.get('YOLOv5_AUTOINSTALL').lower() == 'false': + install = False prefix = colorstr('red', 'bold', 'requirements:') check_python() # check python version if isinstance(requirements, (str, Path)): # requirements.txt file From 11861490459cdea513890ef2b0325a3971e920b8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 20 Apr 2022 12:03:11 -0700 Subject: [PATCH 2/2] Cleanup --- utils/general.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utils/general.py b/utils/general.py index 0631e366248b..92e3560de8c0 100755 --- a/utils/general.py +++ b/utils/general.py @@ -40,6 +40,7 @@ ROOT = FILE.parents[1] # YOLOv5 root directory DATASETS_DIR = ROOT.parent / 'datasets' # YOLOv5 datasets directory NUM_THREADS = min(8, max(1, os.cpu_count() - 1)) # number of YOLOv5 multiprocessing threads +AUTOINSTALL = str(os.getenv('YOLOv5_AUTOINSTALL', True)).lower() == 'true' # global auto-install mode VERBOSE = str(os.getenv('YOLOv5_VERBOSE', True)).lower() == 'true' # global verbose mode FONT = 'Arial.ttf' # https://ultralytics.com/assets/Arial.ttf @@ -322,8 +323,6 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals @try_except def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True): # Check installed dependencies meet requirements (pass *.txt file or list of packages) - if os.environ.get('YOLOv5_AUTOINSTALL').lower() == 'false': - install = False prefix = colorstr('red', 'bold', 'requirements:') check_python() # check python version if isinstance(requirements, (str, Path)): # requirements.txt file @@ -340,7 +339,7 @@ def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), insta pkg.require(r) except Exception: # DistributionNotFound or VersionConflict if requirements not met s = f"{prefix} {r} not found and is required by YOLOv5" - if install: + if install and AUTOINSTALL: # check environment variable LOGGER.info(f"{s}, attempting auto-update...") try: assert check_online(), f"'pip install {r}' skipped (offline)"