Skip to content

Commit

Permalink
Add check_python() (#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
  • Loading branch information
glenn-jocher committed May 9, 2021
1 parent 91547ed commit 57b0d3a
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 @@ -107,10 +108,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

2 comments on commit 57b0d3a

@metaperson
Copy link

@metaperson metaperson commented on 57b0d3a May 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of mine using NVIDIA Jetson with python '3.6.9'.
it makes me get an error to run.
minimum requirement '3.7.0' which you set is too high, even you noticed me on the README.md that requires >3.8.
in Jetson my platform, it is hard (almost impossible) to up the python to '3.7.0'.
the information for Jetson is at the URL below.
https://www.nvidia.com/en-us/autonomous-machines/embedded-systems/jetson-agx-xavier/

I got this message below when I run detect.py.

Traceback (most recent call last):
File "detect.py", line 174, in
check_requirements(exclude=('tensorboard', 'pycocotools', 'thop'))
File "/home/user/yolo/v5/utils/general.py", line 123, in check_requirements
check_python() # check python version
File "/home/user/yolo/v5/utils/general.py", line 116, in check_python
assert result, f'Python {minimum} required by YOLOv5, but Python {current} is currently installed'
AssertionError: Python 3.7.0 required by YOLOv5, but Python 3.6.9 is currently installed

I edited the general.py like below the line around check_requirements().

def check_requirements(requirements='requirements.txt', exclude=()):
    # Check installed dependencies meet requirements (pass *.txt file or list of packages)
    prefix = colorstr('red', 'bold', 'requirements:')
    check_python('3.6.9')  # check python version <== I edited here
    if isinstance(requirements, (str, Path)):  # requirements.txt file
        file = Path(requirements)
        if not file.exists():

then I got run successfully as below without any error.

YOLOv5 🚀 v5.0-90-g06372b1 torch 1.8.0 CUDA:0 (Xavier, 31920.66015625MB)

Fusing layers...
Model Summary: 308 layers, 21356877 parameters, 0 gradients
image 1/2 /home/user/yolo/v5/data/images/bus.jpg: 640x480 4 persons, 1 bus, Done. (0.064s)
image 2/2 /home/user/yolo/v5/data/images/zidane.jpg: 384x640 2 persons, 1 tie, Done. (0.060s)
Results saved to runs/detect/exp3
Done. (0.285s)

could you review the requirements needing python '3.7.0'?

@glenn-jocher
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@metaperson thanks for the feedback! We actually have a jetson nano competition coming up so that's good to know it requires 3.6.9!

Can you submit a PR with this update, and then I'll test the PR. Thanks!

Please sign in to comment.