-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnb_install.py
More file actions
122 lines (109 loc) · 3.87 KB
/
nb_install.py
File metadata and controls
122 lines (109 loc) · 3.87 KB
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
import importlib.util
import sys
import os
import subprocess
def installer():
modules_list = [
"notebook",
"matplotlib",
"pandas",
"seaborn",
"numpy",
"scipy",
"statsmodels",
"-U scikit-learn",
"ipykernel",
"nb-black",
"importlib.util",
"sys",
"os",
"importlib.util",
"subprocess",
"warnings",
"statsmodels.tools.sm_exceptions",
"matplotlib.pyplot",
"sklearn.model_selection.train_test_split",
"statsmodels.stats.api",
"statsmodels.stats.outliers_influence",
"statsmodels.api",
"statsmodels.tools.tools",
"sklearn.tree.DecisionTreeClassifier",
"sklearn.tree",
"sklearn.model_selection.GridSearchCV",
"sklearn.metrics.f1_score",
"sklearn.metrics.accuracy_score",
"sklearn.metrics.recall_score",
"sklearn.metrics.precision_score",
"sklearn.metrics.confusion_matrix",
"sklearn.metrics.roc_auc_score",
"sklearn.metrics.ConfusionMatrixDisplay",
"sklearn.metrics.precision_recall_curve",
"sklearn.metrics.roc_curve",
"sklearn.metrics.make_scorer",
"sklearn.metrics", # new
"from sklearn.ensemble.BaggingClassifier", # new
"RandomForestClassifier", # new
"sklearn.linear_model.LogisticRegression", # new
]
uninstalled_list = []
modules_list_modified = []
unchecked_formatted_list = []
def stringifier(string):
string = string[3:15]
return string
def sort_output(name):
string = name #
# module
if string == "-U scikit-learn":
module = stringifier(string) # string = string[2:15] #
return module
# now have holder=scikit-learn
else:
module = string
return string
def loop_unformatted_packages(modules_list):
for name in modules_list: # '-U scikit-learn'
unchecked_formatted_list.append(sort_output(name))
return unchecked_formatted_list
unchecked_formatted_list = loop_unformatted_packages(modules_list)
def check_not_installed(name):
"""
Check if a package (formatted) is installed or not.
"""
if name in sys.modules:
print(f"{name!r} already in sys.modules")
elif (spec := importlib.util.find_spec(name)) is not None:
# If you choose to perform the actual import ..
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)
print(f"{name!r} has been imported")
else:
print(f"can't find the {name!r} module")
return name
def loop_formatted_packages(unchecked_formatted_list, uninstalled_list):
"""
takes:
- var unchecked_formatted_list
- var uninstalled_list
calls:
- function check_not_installed
"""
for name in unchecked_formatted_list: # '-U scikit-learn'
if check_not_installed(name):
uninstalled_list.append(name)
return uninstalled_list
uninstalled_list = loop_formatted_packages(
unchecked_formatted_list, uninstalled_list
)
print("\nuninstalled modules are:", uninstalled_list, "\n")
newly_installed = []
def installer(uninstalled_list):
for name in uninstalled_list:
if name == "scikit-learn":
name2 = "-U " + name
os.system("pip install {}".format(name2))
print(name, "module has been installed")
newly_installed.append(name)
print("\n", newly_installed, "modules have just been installed")
installer(uninstalled_list)