-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcheck_env.py
More file actions
87 lines (75 loc) · 2.66 KB
/
check_env.py
File metadata and controls
87 lines (75 loc) · 2.66 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
import importlib
import sys
__author__ = "Wim R.M. Cardoen"
__version__ = "2024"
# Last update: 08/22/2024
# Dictionary with the comparaison operators
dictCmp={"==": '__eq__',
"<=": '__le__',
"<" : '__lt__',
">" : '__gt__',
">=": '__ge__',
"!=": '__ne__',
}
def get_pyversion():
"""
Retrieve:
a.Version of Python
b.Installation prefix
"""
version = sys.version_info[0:3]
print(" Python {0}.{1}.{2} found".format(version[0],
version[1],version[2]))
print(" --prefix={0}\n".format(sys.prefix))
if int(version[0]) !=3 or int(version[1]) < 6:
str_err= " ERROR: Python >=3.6 is REQUIRED!"
sys.exit(str_err)
return
def check_package(pkg,op,req_version):
"""
Function which checks:
a. whether a package is installed
b. if the package is installed it also checks
whether it fulfills the requirements.
Return: isOK (boolean)
"""
isOK = False
try:
mod = importlib.import_module(pkg)
isOK = getattr(mod.__version__,dictCmp[op])(req_version)
if isOK:
print(" {0:>15s} inst.:{1:>10s} {2:>2s} req.:{3:>10s} -> OK ".\
format(pkg,mod.__version__, op, req_version))
else:
print(" {0:>15s} inst.:{1:>10s} !{2:>2s} req.:{3:>10s} -> FAIL ".\
format(pkg,mod.__version__, op, req_version))
except ImportError:
print(" {0:>15s} can't be found -> FAIL ".\
format(pkg))
return isOK
if __name__ == "__main__":
# --- Start Requirements SPECIFIC for the NumPy/SciPy tutorial
# which means:
# numpy>=2.0.0
# scipy>=1.14.0
# matplotlib>=3.9.0
# jupyterlab>=4.2.0
REQUIRED_PKG = ['numpy','scipy','matplotlib','jupyterlab']
CMP_OP = ['>=', '>=','>=','>=']
REQUIRED_VERSION = ['2.0.0','1.14.0','3.9.0','4.2.0']
# --- End of the Tutorial Requirements
print("\n\n Checking installation ...\n")
get_pyversion()
statLst = []
for ipkg in range(len(REQUIRED_PKG)):
status = check_package(REQUIRED_PKG[ipkg],CMP_OP[ipkg],REQUIRED_VERSION[ipkg])
statLst.append(int(status))
if sum(statLst) == len(REQUIRED_PKG):
print("\n All required packages are installed")
print(" Congratulations!")
else:
print("\n Some of the required packages either " +
"can't be found\n" +
" or don't have the required version.")
print(" Please CHECK your installation!")
print("\n End checking installation\n")