EVA787797 commited on
Commit
3a50ad6
·
verified ·
1 Parent(s): b0af55b

Upload install.py

Browse files
Files changed (1) hide show
  1. install.py +77 -0
install.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import importlib.util
4
+ import subprocess
5
+ import sys
6
+ from importlib.metadata import version # python >= 3.8
7
+
8
+ from packaging.version import parse
9
+
10
+ import_name = {"py-cpuinfo": "cpuinfo", "protobuf": "google.protobuf"}
11
+
12
+
13
+ def is_installed(
14
+ package: str, min_version: str | None = None, max_version: str | None = None
15
+ ):
16
+ name = import_name.get(package, package)
17
+ try:
18
+ spec = importlib.util.find_spec(name)
19
+ except ModuleNotFoundError:
20
+ return False
21
+
22
+ if spec is None:
23
+ return False
24
+
25
+ if not min_version and not max_version:
26
+ return True
27
+
28
+ if not min_version:
29
+ min_version = "0.0.0"
30
+ if not max_version:
31
+ max_version = "99999999.99999999.99999999"
32
+
33
+ try:
34
+ pkg_version = version(package)
35
+ return parse(min_version) <= parse(pkg_version) <= parse(max_version)
36
+ except Exception:
37
+ return False
38
+
39
+
40
+ def run_pip(*args):
41
+ subprocess.run([sys.executable, "-m", "pip", "install", *args], check=True)
42
+
43
+
44
+ def install():
45
+ deps = [
46
+ # requirements
47
+ ("ultralytics", "8.2.0", None),
48
+ ("mediapipe", "0.10.13", None),
49
+ ("rich", "13.0.0", None),
50
+ ]
51
+
52
+ pkgs = []
53
+ for pkg, low, high in deps:
54
+ if not is_installed(pkg, low, high):
55
+ if low and high:
56
+ cmd = f"{pkg}>={low},<={high}"
57
+ elif low:
58
+ cmd = f"{pkg}>={low}"
59
+ elif high:
60
+ cmd = f"{pkg}<={high}"
61
+ else:
62
+ cmd = pkg
63
+ pkgs.append(cmd)
64
+
65
+ if pkgs:
66
+ run_pip(*pkgs)
67
+
68
+
69
+ try:
70
+ import launch
71
+
72
+ skip_install = launch.args.skip_install
73
+ except Exception:
74
+ skip_install = False
75
+
76
+ if not skip_install:
77
+ install()