Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install=True argument to check_requirements #4512

Merged
merged 2 commits into from
Aug 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals


@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)
prefix = colorstr('red', 'bold', 'requirements:')
check_python() # check python version
Expand All @@ -188,13 +188,17 @@ def check_requirements(requirements='requirements.txt', exclude=()):
try:
pkg.require(r)
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...")
try:
assert check_online(), f"'pip install {r}' skipped (offline)"
print(check_output(f"pip install '{r}'", shell=True).decode())
n += 1
except Exception as e:
print(f'{prefix} {e}')
s = f"{prefix} {r} not found and is required by YOLOv5"
if install:
print(f"{s}, attempting auto-update...")
try:
assert check_online(), f"'pip install {r}' skipped (offline)"
print(check_output(f"pip install '{r}'", shell=True).decode())
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
source = file.resolve() if 'file' in locals() else requirements
Expand Down