-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.py
59 lines (50 loc) · 1.86 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
import os
import subprocess
import sys
import importlib.util
import time
def is_package_installed(package_name):
"""检查包是否已安装"""
return importlib.util.find_spec(package_name) is not None
def install_requirements():
"""安装依赖"""
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt")
if not os.path.exists(requirements_path):
print("未找到 requirements.txt 文件")
return False
required_packages = {
"numpy": "1.21.0",
"Pillow": "9.0.0",
"torch": "1.7.0",
"gradio": "4.0.0"
}
need_install = False
try:
for package, min_version in required_packages.items():
if not is_package_installed(package):
print(f"正在安装 {package}>={min_version}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", f"{package}>={min_version}"])
need_install = True
time.sleep(1) # 等待安装完成
print(f"成功安装 {package}")
return need_install
except subprocess.CalledProcessError as e:
print(f"安装依赖时出错: {e}")
return False
def setup():
"""在 ComfyUI 启动时执行安装"""
if install_requirements():
print("\n" + "="*50)
print("Gradio has been installed successfully!")
print("Please restart ComfyUI to complete the installation.")
if os.name == 'nt':
print("\nOn Windows:")
print("1. Close the current window")
print("2. Run run_cpu.bat or run_gpu.bat again")
else:
print("\nOn Linux/Mac:")
print("1. Press Ctrl+C to stop the current process")
print("2. Run python main.py again")
print("="*50 + "\n")
if __name__ == "__main__":
setup()