-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.py
30 lines (23 loc) · 839 Bytes
/
install.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
import importlib.metadata
import os
import subprocess
import sys
def install_requirements():
requirements_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "requirements.txt"
)
with open(requirements_path) as f:
required = f.read().splitlines()
installed = {
dist.metadata["Name"]: dist.version
for dist in importlib.metadata.distributions()
}
missing = [pkg for pkg in required if pkg.split(">=")[0] not in installed]
if missing:
print(f"Installing missing packages: {', '.join(missing)}")
subprocess.check_call([sys.executable, "-m", "pip", "install", *missing])
print("All requirements installed successfully!")
else:
print("All requirements already satisfied!")
if __name__ == "__main__":
install_requirements()