-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
check_setup.py
48 lines (40 loc) · 1.29 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
46
47
48
"""Check if runtime dependencies are installed.
The script currently does not check for specified optional requirements, e.g.
'scikit-image[data]'.
"""
import sys
import os
from packaging.version import parse
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(os.path.join(os.path.dirname(__file__), '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[data]': 'skimage',
'scikit-image': 'skimage',
'scikit-learn': 'sklearn'
}
for (pkg, version_wanted) in reqs:
module_name = pkg_names.get(pkg, pkg)
try:
m = __import__(module_name)
version_installed = m.__version__
if parse(version_wanted) > parse(version_installed):
status = 'X'
else:
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'
print(
'[{}] {:<20} {}'.format(status, pkg.ljust(13), version_installed)
)