-
Notifications
You must be signed in to change notification settings - Fork 14
/
install.py
70 lines (56 loc) · 1.89 KB
/
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
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
import subprocess
import os
import sys
def run(command, desc=None):
if desc is not None:
print(desc)
# Join the command list into a single string if it's a list
if isinstance(command, list):
command = " ".join(command)
process = subprocess.run(command, shell=True, capture_output=False)
if process.returncode != 0:
print(f"Error running command: {command}")
print(f"Error code: {process.returncode}")
sys.exit(1)
def install_package(package, command):
if not is_installed(package):
run(command, f"Installing {package}")
def is_installed(package):
try:
subprocess.run(
f"{sys.executable} -m pip show {package}",
shell=True,
capture_output=True,
check=True,
)
return True
except subprocess.CalledProcessError:
return False
def prepare_environment():
# Install PyTorch
# Use cuda 11.8 here for consistency with onnxruntime but that
# does not really matter since they use cuda from different places anyway
install_package(
"torch",
(
f"{sys.executable} -m pip install torch torchvision torchaudio "
"--index-url https://download.pytorch.org/whl/cu118"
),
)
# Install other requirements from requirements.txt
requirements_path = os.path.join(os.getcwd(), "requirements.txt")
if os.path.exists(requirements_path):
run(
f"{sys.executable} -m pip install -r {requirements_path}",
"Installing requirements from requirements.txt",
)
# Install waifuc package
waifuc_path = os.path.join(os.getcwd(), "waifuc")
if os.path.exists(waifuc_path):
os.chdir(waifuc_path)
run(
f"{sys.executable} -m pip install .",
"Installing waifuc package",
)
if __name__ == "__main__":
prepare_environment()