Upload install_modules.py
Browse files- install_modules.py +138 -0
install_modules.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
import urllib.request
|
| 5 |
+
|
| 6 |
+
def colored(text, color):
|
| 7 |
+
"""
|
| 8 |
+
Функция для вывода цветного текста в консоль.
|
| 9 |
+
"""
|
| 10 |
+
colors = {
|
| 11 |
+
'red': '\033[91m',
|
| 12 |
+
'green': '\033[92m',
|
| 13 |
+
'yellow': '\033[93m',
|
| 14 |
+
'blue': '\033[94m',
|
| 15 |
+
'magenta': '\033[95m',
|
| 16 |
+
'cyan': '\033[96m',
|
| 17 |
+
'white': '\033[97m',
|
| 18 |
+
}
|
| 19 |
+
return colors.get(color, '') + text + '\033[0m'
|
| 20 |
+
|
| 21 |
+
def uninstall_module(module_name, python_path):
|
| 22 |
+
"""
|
| 23 |
+
Функция для деинсталляции модуля.
|
| 24 |
+
"""
|
| 25 |
+
print(colored(f"Удаление модуля {module_name}...", 'red'))
|
| 26 |
+
pip_path = os.path.join(python_path, "Scripts", "pip.exe")
|
| 27 |
+
subprocess.run([
|
| 28 |
+
pip_path,
|
| 29 |
+
"uninstall",
|
| 30 |
+
"-y",
|
| 31 |
+
module_name
|
| 32 |
+
])
|
| 33 |
+
|
| 34 |
+
def download_file(url, filename):
|
| 35 |
+
"""
|
| 36 |
+
Функция для загрузки файла с помощью urllib.request.
|
| 37 |
+
"""
|
| 38 |
+
print(colored(f"Загрузка файла {filename}...", 'red'))
|
| 39 |
+
try:
|
| 40 |
+
with urllib.request.urlopen(url) as response, open(filename, 'wb') as f:
|
| 41 |
+
f.write(response.read())
|
| 42 |
+
print(colored(f"Файл {filename} успешно загружен.", 'red'))
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(colored(f"Ошибка при загрузке файла: {e}", 'red'))
|
| 45 |
+
|
| 46 |
+
def install_module(filename, python_path):
|
| 47 |
+
"""
|
| 48 |
+
Функция для установки модуля из файла .whl.
|
| 49 |
+
"""
|
| 50 |
+
print(colored(f"Установка модуля из {filename}...", 'red'))
|
| 51 |
+
pip_path = os.path.join(python_path, "Scripts", "pip.exe")
|
| 52 |
+
subprocess.run([
|
| 53 |
+
pip_path,
|
| 54 |
+
"install",
|
| 55 |
+
filename
|
| 56 |
+
])
|
| 57 |
+
|
| 58 |
+
def install_from_index(module_name, index_url, python_path):
|
| 59 |
+
"""
|
| 60 |
+
Функция для установки модуля из указанного индекса.
|
| 61 |
+
"""
|
| 62 |
+
print(colored(f"Установка модуля {module_name} с индекса {index_url}...", 'red'))
|
| 63 |
+
pip_path = os.path.join(python_path, "Scripts", "pip.exe")
|
| 64 |
+
subprocess.run([
|
| 65 |
+
pip_path,
|
| 66 |
+
"install",
|
| 67 |
+
"--extra-index-url",
|
| 68 |
+
index_url,
|
| 69 |
+
module_name
|
| 70 |
+
])
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
# Получение пути к текущей директории
|
| 74 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 75 |
+
|
| 76 |
+
# Создание полного пути к папке Python
|
| 77 |
+
python_path = os.path.join(current_dir, "python_embeded")
|
| 78 |
+
|
| 79 |
+
# Определение путей к git
|
| 80 |
+
git_path = os.path.join(current_dir, "git")
|
| 81 |
+
git_bin_path = os.path.join(git_path, "bin")
|
| 82 |
+
git_libexec_path = os.path.join(git_path, "libexec")
|
| 83 |
+
|
| 84 |
+
# Обновление переменной PATH
|
| 85 |
+
os.environ['PATH'] = f"{git_bin_path};{git_libexec_path};{os.environ['PATH']}"
|
| 86 |
+
|
| 87 |
+
# Установка Comfy
|
| 88 |
+
print(colored("Установка Comfy", 'red'))
|
| 89 |
+
git_exe_path = os.path.join(git_bin_path, "git.exe")
|
| 90 |
+
|
| 91 |
+
subprocess.run([
|
| 92 |
+
git_exe_path,
|
| 93 |
+
"clone",
|
| 94 |
+
"https://github.com/comfyanonymous/ComfyUI"
|
| 95 |
+
])
|
| 96 |
+
|
| 97 |
+
# Обновление
|
| 98 |
+
modules_to_uninstall = ["numpy", "onnxruntime", "onnxruntime-gpu", "torch", "torchvision", "torchaudio"]
|
| 99 |
+
for module in modules_to_uninstall:
|
| 100 |
+
uninstall_module(module, python_path)
|
| 101 |
+
|
| 102 |
+
# Обновление модуля pip
|
| 103 |
+
print(colored("Установка модуля numpy==1.26.4...", 'red'))
|
| 104 |
+
pip_path = os.path.join(python_path, "Scripts", "pip.exe")
|
| 105 |
+
subprocess.run([
|
| 106 |
+
pip_path, # Добавлен путь к pip.exe
|
| 107 |
+
"install",
|
| 108 |
+
"--upgrade",
|
| 109 |
+
"pip"
|
| 110 |
+
])
|
| 111 |
+
|
| 112 |
+
# Установка numpy==1.26.4
|
| 113 |
+
print(colored("Установка модуля numpy==1.26.4...", 'red'))
|
| 114 |
+
pip_path = os.path.join(python_path, "Scripts", "pip.exe")
|
| 115 |
+
subprocess.run([
|
| 116 |
+
pip_path, # Добавлен путь к pip.exe
|
| 117 |
+
"install",
|
| 118 |
+
"numpy==1.26.4"
|
| 119 |
+
])
|
| 120 |
+
|
| 121 |
+
# Загрузка файла insightface-0.7.3-cp311-cp311-win_amd64.whl
|
| 122 |
+
url = "https://github.com/Gourieff/Assets/raw/main/Insightface/insightface-0.7.3-cp311-cp311-win_amd64.whl"
|
| 123 |
+
filename = "insightface-0.7.3-cp311-cp311-win_amd64.whl"
|
| 124 |
+
download_file(url, filename)
|
| 125 |
+
|
| 126 |
+
# Установка модуля из файла .whl
|
| 127 |
+
install_module(filename, python_path)
|
| 128 |
+
|
| 129 |
+
# Установка onnxruntime-gpu из сетевого ресурса
|
| 130 |
+
onnxruntime_index = "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/"
|
| 131 |
+
install_from_index("onnxruntime-gpu", onnxruntime_index, python_path)
|
| 132 |
+
|
| 133 |
+
pytorch_index = "https://download.pytorch.org/whl/cu124"
|
| 134 |
+
install_from_index("torch", pytorch_index, python_path)
|
| 135 |
+
install_from_index("torchvision", pytorch_index, python_path)
|
| 136 |
+
install_from_index("torchaudio", pytorch_index, python_path)
|
| 137 |
+
|
| 138 |
+
print(colored("Установка завершена.", 'green'))
|