-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_setup.py
45 lines (37 loc) · 1.21 KB
/
check_setup.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
import sys
from distutils.version import LooseVersion
if sys.version_info.major < 3:
print('[!] You are running an old version of Python. '
'This tutorial requires Python 3.')
sys.exit(1)
with open('requirements.txt') as f:
reqs = f.readlines()
reqs = [(pkg, ver) for (pkg, _, ver) in
(req.split() for req in reqs if req.strip())]
pkg_names = {
'scikit-image': 'skimage',
'scikit-learn': 'sklearn'
}
for (pkg, version_wanted) in reqs:
module_name = pkg_names.get(pkg, pkg)
try:
m = __import__(module_name)
status = '✓'
except ImportError as e:
m = None
if (pkg != 'numpy' and 'numpy' in str(e)):
status = '?'
version_installed = 'Needs NumPy'
else:
version_installed = 'Not installed'
status = 'X'
if m is not None:
try:
version_installed = m.__version__
except AttributeError: # specific for ITK version
version_installed = m.Version.GetITKVersion()
if LooseVersion(version_wanted) > LooseVersion(version_installed):
status = 'X'
print('[{}] {:<11} {}'.format(
status, pkg.ljust(13), version_installed)
)