-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathcheck_env.py
77 lines (68 loc) · 2.2 KB
/
check_env.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
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
"""
Check for required dependencies for the workshop.
Usage::
% python check_env.py
"""
from packaging.version import Version
# NOTE: Update minversion values as needed.
# This should match environment.yml and requirements.txt contents.
PKGS = {'IPython': '8.0',
'cython': None,
'jupyter': None,
'notebook': '7.0',
'numpy': '1.26',
'scipy': '1.11',
'skimage': '0.22',
'matplotlib': '3.8',
'pandas': '2.1',
'bs4': None, # beautifulsoup4
'keyring': None,
'html5lib': None,
'xlwt': None,
'xlrd': None,
'requests': None,
'jupyterlab': None,
'nbgitpuller': None,
'astropy': '6.0',
'asdf': None,
'gwcs': '0.20',
'ccdproc': '2.4',
'photutils': '1.10.0',
'specutils': '1.12.0',
'astroquery': '0.4.7dev9008',
'openpyxl': None}
def check_package(package_name, minimum_version=None, verbose=True):
errors = False
try:
pkg = __import__(package_name)
except ImportError as err:
print(f'Error: Failed import: {err}')
errors = True
else:
if package_name in ('jupyter', 'keyring'):
installed_version = ''
elif package_name == 'xlwt':
installed_version = pkg.__VERSION__
else:
installed_version = pkg.__version__
if (minimum_version is not None and
Version(installed_version) <
Version(str(minimum_version))):
print(f'Error: {package_name} version {minimum_version} or '
f'later is required, you have version {installed_version}')
errors = True
if not errors and verbose:
print('Found', package_name, installed_version)
return errors
def run_checks():
errors = []
for package_name, min_version in PKGS.items():
errors.append(check_package(package_name, minimum_version=min_version))
if any(errors):
print('\nThere are errors that you must resolve before running the '
'tutorials.')
else:
print('\nYour Python environment is good to go!')
if __name__ == '__main__':
run_checks()