glenn-jocher commited on
Commit
57b0d3a
1 Parent(s): 91547ed

Add check_python() (#3088)

Browse files

* Add check_python()

Checks python version against minimum version of 3.7.0.

* remove packaging dependency

* refactor import

Files changed (1) hide show
  1. utils/general.py +11 -1
utils/general.py CHANGED
@@ -16,6 +16,7 @@ from pathlib import Path
16
  import cv2
17
  import numpy as np
18
  import pandas as pd
 
19
  import torch
20
  import torchvision
21
  import yaml
@@ -107,10 +108,19 @@ def check_git_status():
107
  print(e)
108
 
109
 
 
 
 
 
 
 
 
 
 
110
  def check_requirements(requirements='requirements.txt', exclude=()):
111
  # Check installed dependencies meet requirements (pass *.txt file or list of packages)
112
- import pkg_resources as pkg
113
  prefix = colorstr('red', 'bold', 'requirements:')
 
114
  if isinstance(requirements, (str, Path)): # requirements.txt file
115
  file = Path(requirements)
116
  if not file.exists():
 
16
  import cv2
17
  import numpy as np
18
  import pandas as pd
19
+ import pkg_resources as pkg
20
  import torch
21
  import torchvision
22
  import yaml
 
108
  print(e)
109
 
110
 
111
+ def check_python(minimum='3.7.0', required=True):
112
+ # Check current python version vs. required python version
113
+ current = platform.python_version()
114
+ result = pkg.parse_version(current) >= pkg.parse_version(minimum)
115
+ if required:
116
+ assert result, f'Python {minimum} required by YOLOv5, but Python {current} is currently installed'
117
+ return result
118
+
119
+
120
  def check_requirements(requirements='requirements.txt', exclude=()):
121
  # Check installed dependencies meet requirements (pass *.txt file or list of packages)
 
122
  prefix = colorstr('red', 'bold', 'requirements:')
123
+ check_python() # check python version
124
  if isinstance(requirements, (str, Path)): # requirements.txt file
125
  file = Path(requirements)
126
  if not file.exists():