-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall_requirements.py
73 lines (62 loc) · 2.51 KB
/
install_requirements.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
import subprocess
import sys
import get_pip
import os
import importlib
import contextlib
def install(package):
"""Installs a package using pip.
Package must be a string.
"""
subprocess.call([sys.executable, "-m", "pip", "install", package])
required = ["bs4", "chromedriver", "lxml", "openpyxl", "pandas", "PyQt5", \
"PyQtWebEngine", "requests", "selenium", "sqlite3"]
failed = []
if len(required) > 0:
print(f"You are about to install {len(required)}" + \
" packages, would you like to proceed? (y/n):", end=" ")
ans = input()
if ans.lower() in ["y", "yes", "", " "]:
for package in required:
try:
print("\n[LOG] Looking for ", package)
with contextlib.redirect_stdout(None):
__import__(package)
print(f"[LOG] {package} is already installed, skipping...")
except RuntimeError:
if package == "chromedriver":
print(f"[LOG] {package} is already installed, skipping...")
except ImportError:
print(f"[LOG] {package} not installed.")
try:
print(f"[LOG] Trying to install {package} via pip.")
try:
import pip
except:
print("[EXCEPTION] Pip is not installed.")
print("[LOG] Trying to install pip...")
get_pip.main()
print("[LOG] Pip has been installed!")
print(f"[LOG] Installing {package}")
install(package)
with contextlib.redirect_stdout(None):
if package not in ("PyQtWebEngine", "chromedriver"):
__import__(package)
print(f"[LOG] {package} has been installed")
except Exception as e:
print(f"[ERROR] Could not install {package}: {e}")
failed.append(package)
else:
print("[STOP] Operation terminated by user.")
else:
print("[LOG] No packages to install!")
if len(failed) > 0:
print(f"\n[FAILED] {len(failed)} package(s) were not installed." + \
"\nFailed package install(s):", end=" ")
for x, package in enumerate(failed):
if x != len(failed) -1:
print(package, end=", ")
else:
print(package)
else:
print(f"\n[SUCCESS] {len(required)} package(s) available on machine!")