MCPcopy
hub / github.com/ultralytics/yolov5 / check_requirements

Function check_requirements

utils/general.py:382–413  ·  view source on GitHub ↗
(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds='')

Source from the content-addressed store, hash-verified

380
381@TryExcept()
382def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds=''):
383 # Check installed dependencies meet YOLOv5 requirements (pass *.txt file or list of packages or single package str)
384 prefix = colorstr('red', 'bold', 'requirements:')
385 check_python() # check python version
386 if isinstance(requirements, Path): # requirements.txt file
387 file = requirements.resolve()
388 assert file.exists(), f"{prefix} {file} not found, check failed."
389 with file.open() as f:
390 requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(f) if x.name not in exclude]
391 elif isinstance(requirements, str):
392 requirements = [requirements]
393
394 s = ''
395 n = 0
396 for r in requirements:
397 try:
398 pkg.require(r)
399 except (pkg.VersionConflict, pkg.DistributionNotFound): # exception if requirements not met
400 s += f'"{r}" '
401 n += 1
402
403 if s and install and AUTOINSTALL: # check environment variable
404 LOGGER.info(f"{prefix} YOLOv5 requirement{'s' * (n > 1)} {s}not found, attempting AutoUpdate...")
405 try:
406 # assert check_online(), "AutoUpdate skipped (offline)"
407 LOGGER.info(check_output(f'pip install {s} {cmds}', shell=True).decode())
408 source = file if 'file' in locals() else requirements
409 s = f"{prefix} {n} package{'s' * (n > 1)} updated per {source}\n" \
410 f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
411 LOGGER.info(s)
412 except Exception as e:
413 LOGGER.warning(f'{prefix} ❌ {e}')
414
415
416def check_img_size(imgsz, s=32, floor=0):

Callers 15

runFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
export_onnxFunction · 0.90
export_openvinoFunction · 0.90
export_paddleFunction · 0.90
export_coremlFunction · 0.90
export_engineFunction · 0.90
export_saved_modelFunction · 0.90
export_tfjsFunction · 0.90
mainFunction · 0.90
_createFunction · 0.90

Calls 3

colorstrFunction · 0.85
check_pythonFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected