-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.py
54 lines (47 loc) · 2.51 KB
/
installer.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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm # used to generate a sequence of colours for plotting
from scipy.optimize import curve_fit
from IPython.display import HTML as html_print
from IPython.display import display, Markdown, Latex
###############################################################################
# For printing outputs in colour (copied from Stack Overflow) #
# - modified 20220607 #
###############################################################################
# Start the 'cstr' function.
def cstr(s, color = 'black'):
return "<text style=color:{}>{}</text>".format(color, s)
###############################################################################
# Check to see if required packages are already installed. #
# If not, then install them. #
# - modified 20220907 #
###############################################################################
# Start the 'Check' function.
def Check():
import importlib.util
import sys
import subprocess
cnt = 0
package_names = ['ipysheet', 'uncertainties', 'httpimport', 'pdfkit', 'PyPDF2']
for name in package_names:
spec = importlib.util.find_spec(name)
if spec is None:
display(html_print(cstr('Installing some packages ...\n', color = 'red')))
display(html_print(cstr('After the installation completes, please completely log out and then login again before proceeding.\n', color = 'red')))
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', name])
cnt += 1
import importlib
try:
importlib.import_module('otter')
except ImportError:
display(html_print(cstr('Installing some packages ...\n', color = 'red')))
display(html_print(cstr('After the installation completes, please completely log out and then login again before proceeding.\n', color = 'red')))
import pip
pip.main(['install', 'otter-grader'])
cnt += 1
finally:
globals()['otter'] = importlib.import_module('otter')
if cnt == 0:
display(html_print(cstr('All packages already installed. Please proceed.', color = 'black')))
else:
display(html_print(cstr('\n Some packages were installed. Please completely log out and then login again before proceeding.', color = 'red')))