-
Notifications
You must be signed in to change notification settings - Fork 51
/
check_install.py
62 lines (53 loc) · 1.99 KB
/
check_install.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
import importlib
import sys
from warnings import warn
onpy2 = False
try:
assert sys.version_info >= (3,0)
import importlib.util
except AssertionError:
warn('This tutorial is written for Python 3. Legacy Python is not explicitly supported.')
onpy2 = True
def tuple_version(version):
return tuple(int(x) for x in version.strip('<>+-=.').split('.'))
def check_versions():
version_trouble=False
numba = importlib.import_module('numba')
numba_version = tuple_version(numba.__version__)
if numba_version < (0, 33, 0):
print('Please update Numba to version 0.33.0')
version_trouble=True
mpl = importlib.import_module('matplotlib')
mpl_version = tuple_version(mpl.__version__)
if mpl_version < (2, 0, 0):
print('Please update matplotlib to version 2.0.0 or higher')
version_trouble=True
return version_trouble
def main():
required_modules = ['numpy', 'matplotlib', 'jupyter',
'numba', 'llvmlite', 'line_profiler', 'IPython',]
missing_modules = []
for mod in required_modules:
if not onpy2:
spec = importlib.util.find_spec(mod)
if spec is None:
missing_modules.append(mod)
else:
try:
importlib.import_module(mod)
except ImportError:
missing_modules.append(mod)
if missing_modules:
print('The following modules are required but not installed:')
print(' {}'.format(', '.join(missing_modules)))
print('\nYou can install them using conda by running:')
print('\n conda install {}'.format(' '.join(missing_modules)))
print('\nOr you can install them using pip by running:')
print('\n pip install {}'.format(' '.join(missing_modules)))
else:
if check_versions():
print('All packages are installed but at least one needs updating')
else:
print('Everything looks good!')
if __name__ == '__main__':
main()