(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds='')
| 380 | |
| 381 | @TryExcept() |
| 382 | def 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 | |
| 416 | def check_img_size(imgsz, s=32, floor=0): |
no test coverage detected