-
Notifications
You must be signed in to change notification settings - Fork 164
/
install_check.py
168 lines (134 loc) · 4.91 KB
/
install_check.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import sys
import logging
from subprocess import check_call, CalledProcessError
SUCCESS_PREFIX = '🎉'
FIX_PREFIX = '⚠️⚠️⚠️ ----->'
tutorial_name = 'Jupyter widget ecosystem'
requirements = [
'notebook',
'ipywidgets',
'bqplot',
'ipyleaflet',
'ipyvolume',
'pythreejs',
'ipytree',
'ipydatagrid',
'ipycytoscape',
'ipygany',
'jupyterlab',
'voila',
'pyvista',
'mpl_interactions',
'orjson', # For one of the example in ipycanvas
]
import_result = {p: False for p in requirements}
print("Checking requirements for {}".format(tutorial_name), end='')
for package in requirements:
try:
__import__(package)
import_result[package] = True
except ImportError:
pass
print('.', end='', flush=True)
print()
success = all(import_result.values())
# List compatible versions for each package
version_check_packages = {'ipywidgets': ['7.7'],
'jupyterlab': ['3'],
}
if success:
print(f'\t{SUCCESS_PREFIX} All required packages installed')
else:
print(FIX_PREFIX, 'Please install these missing packages '
'for the tutorial "{}":'.format(tutorial_name))
missing = [k for k, v in import_result.items() if not v]
print('\t' + '\n\t'.join(missing))
print('Checking voila version:')
try:
check_call(['voila', '--version'])
print(f'\t{SUCCESS_PREFIX} Voila is correctly installed')
except CalledProcessError:
print(f'\t {FIX_PREFIX} Voila is not installed! Please install it by running one '
'of the following:')
print(' conda install -c conda-forge voila')
print(' pip install voila')
print('Checking version numbers of these packages: ',
', '.join(version_check_packages.keys()))
def version_checker(package_name, version, nbextension=None):
good_version = any(version.startswith(v) for
v in version_check_packages[package_name])
if nbextension is None:
nbextension = package_name
if not good_version:
newest = version_check_packages[package_name][-1]
print('\n**** Please upgrade {} to version {} by running:'.format(package_name,
newest))
print(' conda install {}={} # if you use conda'.format(package_name, newest))
print(' pip install {}=={}'.format(package_name, newest))
else:
print(f'\t{SUCCESS_PREFIX} {package_name} version is good!')
# Check as many packages as we can...
try:
import ipywidgets
except ImportError:
pass
else:
ipywidgets_version = ipywidgets.__version__
version_checker('ipywidgets', ipywidgets_version)
try:
import jupyterlab
except ImportError:
pass
else:
jupyterlab_version = jupyterlab.__version__
version_checker('jupyterlab', jupyterlab_version)
# Check that the appropriate kernel has been created
required_kernel = 'widgets-tutorial'
print('Checking whether kernel {} exists'.format(required_kernel))
import jupyter_client
known_kernels = list(jupyter_client.kernelspec.find_kernel_specs().keys())
if required_kernel not in known_kernels:
print(FIX_PREFIX, 'Please create custom kernel with: ',
'ipython kernel install --name widgets-tutorial --display-name widgets-tutorial --sys-prefix')
else:
print(f'\t{SUCCESS_PREFIX} Custom kernel is correctly installed')
# Check that lab extensions are installed
print('Checking whether all Jupyter lab extensions are installed')
lab_extensions = [
'@jupyter-widgets/jupyterlab-manager',
'@jupyter-widgets/jupyterlab-sidecar',
'bqplot',
'jupyter-threejs',
'jupyter-leaflet',
'ipyvolume',
'ipytree',
'ipycanvas',
'ipydatagrid',
'ipygany',
'jupyter-cytoscape', # for ipycytoscape
'jupyter-matplotlib',
'jupyter-vuetify',
]
try:
from jupyterlab.commands import check_extension, AppOptions
from jupyterlab_server.config import get_federated_extensions
except ImportError:
print(FIX_PREFIX, 'Please install jupyterlab before checking extensions.')
else:
missing_extensions = []
# Fetch federated extensions
federated_extensions = get_federated_extensions([sys.base_prefix + '/share/jupyter/labextensions']).keys()
# JupyterLab be quiet
logger = logging.Logger('quiet')
logger.setLevel(logging.CRITICAL)
app_options = AppOptions(logger=logger)
for extension in lab_extensions:
if not check_extension(extension, app_options=app_options) and extension not in federated_extensions:
missing_extensions.append(extension)
if missing_extensions:
print(FIX_PREFIX, 'These lab extensions are missing: ',
', '.join(missing_extensions))
print(FIX_PREFIX,' Please try to install the following packages with conda or pip: ',
', '.join(missing_extensions))
else:
print(f'\t{SUCCESS_PREFIX} All extensions are installed!')