2121if sys .platform == "win32" :
2222 BUILDS ["dml" ] = "requirements_dml.txt"
2323
24- # VVVVVV --- ИЗМЕНЕНИЕ 1: Упрощенная и более надежная функция --- VVVVVV
2524def run_command (command , cwd = None ):
2625 """Runs a command, ensuring shell is used for strings."""
2726 is_string = isinstance (command , str )
@@ -30,17 +29,21 @@ def run_command(command, cwd=None):
3029 command ,
3130 stdout = subprocess .PIPE ,
3231 stderr = subprocess .STDOUT ,
33- shell = is_string , # Use shell only for string commands
32+ shell = is_string ,
3433 cwd = cwd ,
3534 text = True ,
36- encoding = 'utf-8'
35+ encoding = 'utf-8' ,
36+ # VVVVVV --- ИЗМЕНЕНИЕ 1: Добавляем executable для Linux/macOS --- VVVVVV
37+ # Это заставляет Popen использовать /bin/bash, который лучше понимает команду 'source' (или '.'),
38+ # чем стандартный /bin/sh.
39+ executable = "/bin/bash" if not is_string and sys .platform != "win32" else None
40+ # ^^^^^^ --- КОНЕЦ ИЗМЕНЕНИЯ 1 --- ^^^^^^
3741 )
3842 for line in process .stdout :
3943 print (line , end = '' )
4044 process .wait ()
4145 if process .returncode != 0 :
4246 raise subprocess .CalledProcessError (process .returncode , command )
43- # ^^^^^^ --- КОНЕЦ ИЗМЕНЕНИЯ 1 --- ^^^^^^
4447
4548def get_onnx_libs_path (venv_path ):
4649 if sys .platform == "win32" :
@@ -56,19 +59,25 @@ def create_and_build(name, req_file):
5659
5760 if sys .platform == "win32" :
5861 python_executable = venv_path / "Scripts" / "python.exe"
59- pip_executable = venv_path / "Scripts" / "pip.exe"
6062 else :
6163 python_executable = venv_path / "bin" / "python"
62- pip_executable = venv_path / "bin" / "pip"
6364
6465 if not venv_path .exists ():
6566 print (f"Creating virtual environment for { name } ..." )
6667 venv .create (venv_path , with_pip = True )
6768
6869 print (f"Installing dependencies for { name } from { req_file } ..." )
6970
70- # VVVVVV --- ИЗМЕНЕНИЕ 2: Вызываем pip напрямую и как строку --- VVVVVV
71- cmd_as_string = f"{ str (pip_executable )} install -r { str (req_file )} "
71+ # VVVVVV --- ИЗМЕНЕНИЕ 2: Формируем команду с активацией venv --- VVVVVV
72+ if sys .platform == "win32" :
73+ activate_script = venv_path / "Scripts" / "activate.bat"
74+ # На Windows используем `call` и `&&` для последовательного выполнения
75+ cmd_as_string = f'call "{ activate_script } " && python -m pip install -r "{ req_file } "'
76+ else :
77+ # На Linux используем `.` (аналог `source`) и `&&`
78+ activate_script = venv_path / "bin" / "activate"
79+ cmd_as_string = f'. "{ activate_script } " && pip install -r "{ req_file } "'
80+
7281 run_command (cmd_as_string )
7382 # ^^^^^^ --- КОНЕЦ ИЗМЕНЕНИЯ 2 --- ^^^^^^
7483
@@ -94,7 +103,6 @@ def create_and_build(name, req_file):
94103
95104 pyinstaller_command .append (str (SRC_FILE ))
96105
97- # Вызываем PyInstaller списком, как и раньше, т.к. это надежнее для сложных команд
98106 run_command (pyinstaller_command )
99107 print (f"--- Successfully built { name } version! ---" )
100108
0 commit comments