-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphyserror_reqs_install.py
More file actions
67 lines (56 loc) · 2.48 KB
/
physerror_reqs_install.py
File metadata and controls
67 lines (56 loc) · 2.48 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
import sys
import subprocess
reqs_dict = {
'numpy': 'numpy',
'pandas[excel]' : ('pandas', 'xlsxwriter', 'openpyxl'),
'matplotlib' : 'matplotlib',
'tk' : 'tk',
'scipy' : 'scipy',
'seaborn' : 'seaborn',
'inquirer' : 'inquirer'
}
def _install(package):
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
def _check_install():
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
installed_packages = [r.decode().split('==')[0] for r in reqs.split()]
return installed_packages
def user_install():
installed_pkgs = _check_install()
for i in range(len(installed_pkgs)):
installed_pkgs[i] = installed_pkgs[i].lower()
title = 'READ FULL MESSAGE BEFORE ANSWERING'
warn_title = f"\n{title:=^73}\n"
warn_msg = (f"{'This file is used to check for installed Python libraries and install' : ^73}\n"
f"{'packages that are not already installed. The packages are not malicious' : ^73}\n"
f"{'in any way and can easily be found by searching their names online.' : ^73}\n"
f"{'However, if you are uncomfortable with this file installing the packages,' : ^73}\n"
f"{'please answer No below.' : ^73}\n")
print(warn_title)
print(warn_msg)
print(f"Required packages: {list(reqs_dict.keys())}")
user_veri = input("If you would like to install the packages, type and enter 'Yes'. Otherwise type and enter 'No': ")
print("")
match user_veri.lower():
case 'yes' | 'y':
for req in reqs_dict:
if type(reqs_dict[req]) == str:
if reqs_dict[req] not in installed_pkgs:
print(f"Installing {req}...\n")
_install(req)
else:
print(f"{req} already installed, continuing...")
else:
for subreq in reqs_dict[req]:
if subreq not in installed_pkgs:
print(f"Installing {req}...\n")
_install(req)
else:
print(f"{req} - {subreq} already installed, continuing...")
case _:
sys.exit("User has cancelled installation.\n")
print("\nRequired packages check complete.")
installed_packages = _check_install()
print(f"\nInstalled packages w/ dependencies:\n{installed_packages}\n")
if __name__ == "__main__":
user_install()