glenn-jocher commited on
Commit
317f2cc
·
unverified ·
1 Parent(s): 563ea94

Improved `check_requirements()` offline-handling (#3466)

Browse files

Improve robustness of `check_requirements()` function to offline environments (do not attempt pip installs when offline).

Files changed (1) hide show
  1. utils/general.py +2 -1
utils/general.py CHANGED
@@ -163,10 +163,11 @@ def check_requirements(requirements='requirements.txt', exclude=()):
163
  try:
164
  pkg.require(r)
165
  except Exception as e: # DistributionNotFound or VersionConflict if requirements not met
166
- n += 1
167
  print(f"{prefix} {r} not found and is required by YOLOv5, attempting auto-update...")
168
  try:
 
169
  print(check_output(f"pip install '{r}'", shell=True).decode())
 
170
  except Exception as e:
171
  print(f'{prefix} {e}')
172
 
 
163
  try:
164
  pkg.require(r)
165
  except Exception as e: # DistributionNotFound or VersionConflict if requirements not met
 
166
  print(f"{prefix} {r} not found and is required by YOLOv5, attempting auto-update...")
167
  try:
168
+ assert check_online(), f"'pip install {r}' skipped (offline)"
169
  print(check_output(f"pip install '{r}'", shell=True).decode())
170
+ n += 1
171
  except Exception as e:
172
  print(f'{prefix} {e}')
173