-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathcheck_project_env.py
More file actions
103 lines (79 loc) · 2.75 KB
/
check_project_env.py
File metadata and controls
103 lines (79 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import sys
import platform
import importlib
from pathlib import Path
print("\n===== OpenVINO Environment Diagnostic =====\n")
# ------------------ SYSTEM INFO ------------------
print("System Information")
print("------------------")
print("OS:", platform.system(), platform.release())
print("Machine:", platform.machine())
print("Processor:", platform.processor())
# ------------------ PYTHON INFO ------------------
print("\nPython Information")
print("------------------")
print("Python version:", sys.version)
# ------------------ OPENVINO INFO ------------------
print("\nOpenVINO Information")
print("------------------")
try:
import openvino as ov
core = ov.Core()
print("OpenVINO version:", ov.__version__)
print("Available devices:")
for device in core.available_devices:
print(" -", device)
except Exception as e:
print("OpenVINO check failed:", e)
# ------------------ PACKAGE CHECK ------------------
print("\nPackage Check")
print("------------------")
req_file = Path("requirements.txt")
# mapping pip names → import names
IMPORT_MAP = {
"pillow": "PIL",
"opencv-python": "cv2",
"optimum-intel": "optimum",
}
def parse_line(line):
"""Extract package name + required version"""
if "==" in line:
name, version = line.split("==")
elif ">=" in line:
name, version = line.split(">=")
else:
name, version = line, None
name = name.strip()
version = version.strip() if version else None
# remove extras like qrcode[pil]
name = name.split("[")[0]
return name, version
if req_file.exists():
packages = []
with open(req_file) as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
if line.startswith("--"):
continue
pkg_name, req_version = parse_line(line)
packages.append((pkg_name, req_version))
for pkg, req_version in packages:
module_name = IMPORT_MAP.get(pkg, pkg.replace("-", "_"))
try:
module = importlib.import_module(module_name)
# try to get installed version
installed_version = getattr(module, "__version__", None)
if req_version and installed_version:
if installed_version.startswith(req_version):
print(f"{pkg} ✔ installed ({installed_version})")
else:
print(f"{pkg} ⚠ version mismatch (installed: {installed_version}, required: {req_version})")
else:
print(f"{pkg} ✔ installed")
except ImportError:
print(f"{pkg} ❌ missing")
else:
print("No requirements.txt found.")
print("\n===========================================\n")