-
Notifications
You must be signed in to change notification settings - Fork 521
/
check_env.py
78 lines (69 loc) · 1.88 KB
/
check_env.py
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
import sys
import importlib
OK = "\x1b[42m[ OK ]\x1b[0m"
FAIL = "\x1b[41m[FAIL]\x1b[0m"
try:
from packaging.version import Version
except ImportError:
print(
FAIL, "'packaging' package not installed, install it with conda or pip"
)
sys.exit(1)
# first check the python version
print("Using python in", sys.prefix)
print(sys.version)
pyversion_str = f"{sys.version_info.major}.{sys.version_info.minor}"
pyversion = Version(pyversion_str)
if pyversion < Version("3.8"):
print(
FAIL,
(
"Python version 3.8 or above is required,"
f" but {pyversion_str} is installed."
),
)
sys.exit(1)
print()
def import_version(pkg, min_ver, fail_msg=""):
mod = None
try:
mod = importlib.import_module(pkg)
if pkg in {"PIL"}:
try:
ver = mod.__version__
except AttributeError:
try:
ver = mod.VERSION
except AttributeError:
try:
ver = mod.PILLOW_VERSION
except Exception:
raise
else:
ver = mod.__version__
if Version(ver) < Version(min_ver):
print(
FAIL,
(
f"{lib} version {min_ver} or higher required, but"
f" {ver} installed."
),
)
else:
print(OK, f"{pkg} version {ver}")
except ImportError:
print(FAIL, f"{pkg} not installed. {fail_msg}")
return mod
requirements = {
"numpy": "1.16",
"scipy": "1.2",
"matplotlib": "3.0",
"sklearn": "1.3",
"pandas": "1",
"seaborn": "0.11",
"notebook": "5.7",
"plotly": "5.10",
}
# now the dependencies
for lib, required_version in list(requirements.items()):
import_version(lib, required_version)