-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathinstall.py
72 lines (61 loc) · 2.33 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
71
72
import launch
import os
import sys
import pkg_resources
from packaging.version import parse
def check_install() -> None:
use_gpu = True
if use_gpu and sys.platform != "darwin":
print("Faceswaplab : Use GPU requirements")
req_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "requirements-gpu.txt"
)
else:
print("Faceswaplab : Use CPU requirements")
req_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "requirements.txt"
)
def is_installed(package: str) -> bool:
package_name = package.split("==")[0].split(">=")[0].strip()
try:
installed_version = parse(
pkg_resources.get_distribution(package_name).version
)
except pkg_resources.DistributionNotFound:
return False
if "==" in package:
required_version = parse(package.split("==")[1])
return installed_version == required_version
elif ">=" in package:
required_version = parse(package.split(">=")[1])
return installed_version >= required_version
else:
if package_name == "opencv-python":
return launch.is_installed(package_name) or launch.is_installed("cv2")
return launch.is_installed(package_name)
print("Checking faceswaplab requirements")
with open(req_file) as file:
for package in file:
try:
package = package.strip()
if not is_installed(package):
print(f"Install {package}")
launch.run_pip(
f"install {package}",
f"sd-webui-faceswaplab requirement: {package}",
)
except Exception as e:
print(e)
print(
f"Warning: Failed to install {package}, faceswaplab may not work. Try to restart server or install dependencies manually."
)
raise e
import timeit
try:
check_time = timeit.timeit(check_install, number=1)
print(check_time)
except Exception as e:
print("FaceswapLab install failed", e)
print(
"You can try to install dependencies manually by activating venv and installing requirements.txt or requirements-gpu.txt"
)