Update check_requirements(args, cmds='') (#9355)
* Update `check_requirements(args, cmds='')` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
24bf9cceb4
commit
e9ddc5b527
2 files changed
+6
-6
No files matched your search
@@ -226,7 +226,7 @@ def export_engine(model, im, file, half, dynamic, simplify, workspace=4, verbose
|
|||||||
import tensorrt as trt
|
import tensorrt as trt
|
||||||
except Exception:
|
except Exception:
|
||||||
if platform.system() == 'Linux':
|
if platform.system() == 'Linux':
|
||||||
check_requirements('nvidia-tensorrt', cmds=['-U --index-url https://pypi.ngc.nvidia.com'])
|
check_requirements('nvidia-tensorrt', cmds='-U --index-url https://pypi.ngc.nvidia.com')
|
||||||
import tensorrt as trt
|
import tensorrt as trt
|
||||||
|
|
||||||
if trt.__version__[0] == '7': # TensorRT 7 handling https://github.com/ultralytics/yolov5/issues/6012
|
if trt.__version__[0] == '7': # TensorRT 7 handling https://github.com/ultralytics/yolov5/issues/6012
|
||||||
|
|||||||
+5
-5
@@ -341,13 +341,13 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals
|
|||||||
|
|
||||||
|
|
||||||
@TryExcept()
|
@TryExcept()
|
||||||
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds=()):
|
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds=''):
|
||||||
# Check installed dependencies meet YOLOv5 requirements (pass *.txt file or list of packages or single package str)
|
# Check installed dependencies meet YOLOv5 requirements (pass *.txt file or list of packages or single package str)
|
||||||
prefix = colorstr('red', 'bold', 'requirements:')
|
prefix = colorstr('red', 'bold', 'requirements:')
|
||||||
check_python() # check python version
|
check_python() # check python version
|
||||||
if isinstance(requirements, Path): # requirements.txt file
|
if isinstance(requirements, Path): # requirements.txt file
|
||||||
file = requirements
|
file = requirements.resolve()
|
||||||
assert file.exists(), f"{prefix} {file.resolve()} not found, check failed."
|
assert file.exists(), f"{prefix} {file} not found, check failed."
|
||||||
with file.open() as f:
|
with file.open() as f:
|
||||||
requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(f) if x.name not in exclude]
|
requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(f) if x.name not in exclude]
|
||||||
elif isinstance(requirements, str):
|
elif isinstance(requirements, str):
|
||||||
@@ -366,8 +366,8 @@ def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), insta
|
|||||||
LOGGER.info(f"{prefix} YOLOv5 requirements {s}not found, attempting AutoUpdate...")
|
LOGGER.info(f"{prefix} YOLOv5 requirements {s}not found, attempting AutoUpdate...")
|
||||||
try:
|
try:
|
||||||
assert check_online(), "AutoUpdate skipped (offline)"
|
assert check_online(), "AutoUpdate skipped (offline)"
|
||||||
LOGGER.info(check_output(f'pip install {s} {" ".join(cmds) if cmds else ""}', shell=True).decode())
|
LOGGER.info(check_output(f'pip install {s} {cmds}', shell=True).decode())
|
||||||
source = file.resolve() if 'file' in locals() else requirements
|
source = file if 'file' in locals() else requirements
|
||||||
s = f"{prefix} {n} package{'s' * (n > 1)} updated per {source}\n" \
|
s = f"{prefix} {n} package{'s' * (n > 1)} updated per {source}\n" \
|
||||||
f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
|
f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
|
||||||
LOGGER.info(s)
|
LOGGER.info(s)
|
||||||
|
|||||||
Reference in new issue
Block a user