-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_setup.py
42 lines (35 loc) · 1.13 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
import sys
import os
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(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': '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:
version_installed = m.__version__
if LooseVersion(version_wanted) > LooseVersion(version_installed):
status = 'X'
print('[{}] {:<11} {}'.format(
status, pkg.ljust(13), version_installed)
)