Skip to content

Commit

Permalink
Add check_python() (ultralytics#3088)
Browse files Browse the repository at this point in the history
* Add check_python()

Checks python version against minimum version of 3.7.0.

* remove packaging dependency

* refactor import

(cherry picked from commit 57b0d3a)
  • Loading branch information
glenn-jocher authored and Lechtr committed May 24, 2021
1 parent c74e91c commit 9235c81
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import cv2
import numpy as np
import pandas as pd
import pkg_resources as pkg
import torch
import torchvision
import yaml
Expand Down Expand Up @@ -110,10 +111,19 @@ def check_git_status():
print(e)


def check_python(minimum='3.7.0', required=True):
# Check current python version vs. required python version
current = platform.python_version()
result = pkg.parse_version(current) >= pkg.parse_version(minimum)
if required:
assert result, f'Python {minimum} required by YOLOv5, but Python {current} is currently installed'
return result


def check_requirements(requirements='requirements.txt', exclude=()):
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
import pkg_resources as pkg
prefix = colorstr('red', 'bold', 'requirements:')
check_python() # check python version
if isinstance(requirements, (str, Path)): # requirements.txt file
file = Path(requirements)
if not file.exists():
Expand Down

0 comments on commit 9235c81

Please sign in to comment.