-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain6.py
115 lines (91 loc) · 2.93 KB
/
main6.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
import importlib.util
import sys
import os
import subprocess
# subprocess.run("chmod +x script2.sh")
# os.chmod("x", "script2.sh")
modules_list = [
"notebook",
"matplotlib",
"pandas",
"seaborn",
"numpy",
"scipy",
"statsmodels",
"-U scikit-learn",
"ipykernel",
"nb-black",
"importlib.util",
"sys",
"os",
]
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)
# os.system("pip install notebook")
# os.system("pip install matplotlib")
# os.system("pip install pandas")
# os.system("pip install seaborn")
# os.system("pip install numpy")
# os.system("pip install scipy")
# os.system("pip install statsmodels")
# os.system("pip install -U scikit-learn")
# os.system("pip install ipykernel")
# os.system("pip install nb-black")
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(newly_installed, "modules have just been installed")
installer(uninstalled_list)