-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathversions.py
executable file
·100 lines (82 loc) · 3 KB
/
versions.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
from __future__ import print_function
from pkg_resources import parse_version
import sys
libraries = {
"python": "3.6",
"numpy": "1.13.3",
"pandas": "0.23.0",
"matplotlib": "2.1.1",
"sklearn": "0.19.1",
"scipy": "0.19.1",
"seaborn": "0.8.0",
"statsmodels": "0.9.0",
"lxml": "4.6.3"
}
installed = {}
missing=[]
old=[]
def helper(name, required_version):
try:
x = __import__(name)
except Exception: # ModuleNotFoundError: # does not work in Python 2
x = None
if x:
if name == "lxml":
from lxml import etree
version = etree.__version__
else:
version = x.__version__
if parse_version(version) < parse_version(required_version):
old.append(name)
installed[name] = (version, x.__file__)
else:
installed[name] = ("-", "-")
missing.append(name)
def max_length(L):
return max(len(x) for x in L)
python_version = ".".join(map(str, sys.version_info[:3]))
#print(python_version)
print("Python version:", sys.version.split('\n')[0])
for library, required_version in libraries.items():
if library == "python":
location = sys.executable
installed[library] = (python_version, location)
if parse_version(python_version) < parse_version(libraries[library]):
old.append(library)
else:
helper(library, required_version)
library_length = max_length(["Library"] + list(installed.keys()))
required_length = max_length(["Required"] + list(libraries.values()))
installed_version_length = max_length(["Installed"] + [ version for version, location in installed.values() ])
#library_length = max([ len(library) for library in installed ])
#installed_version_length = max([ len(version) for version, location in installed.values() ])
#required_length = max([ len(required_version) for required_version in libraries.values() ])
#library_length = max(library_length, len("Library"))
#installed_version_length = max(installed_version_length, len("Installed"))
#required_length = max(required_length, len("Required"))
print("%-*s %*s %*s %s" % (library_length, "Library", installed_version_length, "Installed",
required_length, "Required", "Location"))
for library in installed:
installed_version, location = installed[library]
required = libraries[library]
print("%-*s %*s %*s %s" % (library_length, library,
installed_version_length, installed_version,
required_length, required,
location))
print()
if missing:
print("The following libraries are missing:")
for library in missing:
print(library)
print()
if old:
print("The following libraries are too old:")
for library in old:
print(library)
#print(installed)
print()
if missing or old:
print("Installation is not complete!")
else:
print("Installation is complete!")