-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_install.py
68 lines (56 loc) · 2.13 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
63
64
65
66
67
68
"""
Check the installation for the Scientific visualization workshop on
PyCon 2019
This file is based on the following script:
https://github.com/gforsyth/numba_tutorial_scipy2017/blob/master/check_install.py
that is released under MIT license by Gilbert Forsyth and Lorena Barba.
"""
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
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', 'scipy',
'vtk', 'IPython', 'jupyter', 'mayavi',
'yt', 'ipyvolume', 'spyder', 'PyQt5']
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()