Add `install=True` argument to `check_requirements` (#4512)
* Add `install=True` argument to `check_requirements` * Update general.py
This commit is contained in:
parent
7316b78e36
commit
7b1643b5b5
|
|
@ -172,7 +172,7 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals
|
||||||
|
|
||||||
|
|
||||||
@try_except
|
@try_except
|
||||||
def check_requirements(requirements='requirements.txt', exclude=()):
|
def check_requirements(requirements='requirements.txt', exclude=(), install=True):
|
||||||
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
|
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
|
||||||
prefix = colorstr('red', 'bold', 'requirements:')
|
prefix = colorstr('red', 'bold', 'requirements:')
|
||||||
check_python() # check python version
|
check_python() # check python version
|
||||||
|
|
@ -188,13 +188,17 @@ def check_requirements(requirements='requirements.txt', exclude=()):
|
||||||
try:
|
try:
|
||||||
pkg.require(r)
|
pkg.require(r)
|
||||||
except Exception as e: # DistributionNotFound or VersionConflict if requirements not met
|
except Exception as e: # DistributionNotFound or VersionConflict if requirements not met
|
||||||
print(f"{prefix} {r} not found and is required by YOLOv5, attempting auto-update...")
|
s = f"{prefix} {r} not found and is required by YOLOv5"
|
||||||
try:
|
if install:
|
||||||
assert check_online(), f"'pip install {r}' skipped (offline)"
|
print(f"{s}, attempting auto-update...")
|
||||||
print(check_output(f"pip install '{r}'", shell=True).decode())
|
try:
|
||||||
n += 1
|
assert check_online(), f"'pip install {r}' skipped (offline)"
|
||||||
except Exception as e:
|
print(check_output(f"pip install '{r}'", shell=True).decode())
|
||||||
print(f'{prefix} {e}')
|
n += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(f'{prefix} {e}')
|
||||||
|
else:
|
||||||
|
print(f'{s}. Please install and rerun your command.')
|
||||||
|
|
||||||
if n: # if packages updated
|
if n: # if packages updated
|
||||||
source = file.resolve() if 'file' in locals() else requirements
|
source = file.resolve() if 'file' in locals() else requirements
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue