11import subprocess
22import sys
33import os
4+ import time
45from pathlib import Path
5- import shutil
6-
7- def run_command (command ):
8- try :
9- subprocess .run (command , shell = True , check = True )
10- except subprocess .CalledProcessError as e :
11- print (f"Error running command: { command } " )
12- print (f"Error message: { e } " )
13- sys .exit (1 )
14-
15- def move_file (src , dst ):
16- try :
17- if not src .exists ():
18- print (f"Source file not found: { src } " )
19- return False
20- shutil .move (str (src ), str (dst ))
21- print (f"Moved { src .name } to { dst } " )
22- return True
23- except PermissionError :
24- print (f"Permission denied when trying to move { src } " )
25- except Exception as e :
26- print (f"Error moving { src } : { e } " )
27- return False
286
29- def main ():
30- # Step 1: Upgrade pip, setuptools, and wheel
31- run_command ("python -m pip install --upgrade pip setuptools wheel" )
7+ def install_libraries_with_retry (max_retries = 3 , delay = 3 ):
8+ libraries = [
9+ "av==12.3.0" ,
10+ "CFFI==1.16.0" ,
11+ "certifi==2024.7.4" ,
12+ "chardet==5.2.0" ,
13+ "ctranslate2==4.3.1" ,
14+ "faster-whisper==1.0.2" ,
15+ "filelock==3.15.4" ,
16+ "huggingface-hub==0.24.1" ,
17+ "idna==3.7" ,
18+ "nvidia-cublas-cu12==12.1.3.1" ,
19+ "nvidia-cuda-nvrtc-cu12==12.1.105" ,
20+ "nvidia-cuda-runtime-cu12==12.1.105" ,
21+ "nvidia-cudnn-cu12==8.9.7.29" ,
22+ "numpy==1.26.4" ,
23+ "pycparser==2.22" ,
24+ "PyYAML==6.0.1" ,
25+ "requests==2.32.3" ,
26+ "sounddevice==0.4.7" ,
27+ "tokenizers==0.19.1" ,
28+ "tqdm==4.66.4" ,
29+ "urllib3==2.2.2"
30+ ]
3231
33- # Step 2: Install requirements
34- run_command ( "pip install -r requirements.txt" )
32+ failed_installations = []
33+ multiple_attempts = []
3534
36- # Step 3: Move files
37- current_dir = Path (__file__ ).parent .resolve ()
38- python_lib_path = current_dir / 'Lib' / 'site-packages'
35+ for library in libraries :
36+ for attempt in range (max_retries ):
37+ try :
38+ print (f"\n Attempt { attempt + 1 } of { max_retries } : Installing { library } " )
39+ command = [sys .executable , "-m" , "uv" , "pip" , "install" , library , "--no-deps" , "--no-cache-dir" ]
40+ subprocess .run (command , check = True , capture_output = True , text = True )
41+ print (f"Successfully installed { library } " )
42+ if attempt > 0 :
43+ multiple_attempts .append ((library , attempt + 1 ))
44+ break
45+ except subprocess .CalledProcessError as e :
46+ print (f"Attempt { attempt + 1 } failed. Error: { e .stderr .strip ()} " )
47+ if attempt < max_retries - 1 :
48+ print (f"Retrying in { delay } seconds..." )
49+ time .sleep (delay )
50+ else :
51+ print (f"Failed to install { library } after { max_retries } attempts." )
52+ failed_installations .append (library )
3953
40- files_to_move = [
41- (python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublas64_12.dll' , current_dir ),
42- (python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublasLt64_12.dll' , current_dir ),
43- (python_lib_path / 'nvidia' / 'cudnn' / 'bin' / 'cudnn_cnn_infer64_8.dll' , current_dir )
44- ]
54+ print ("\n --- Installation Summary ---" )
55+ if failed_installations :
56+ print ("\n The following libraries failed to install:" )
57+ for lib in failed_installations :
58+ print (f"- { lib } " )
59+
60+ if multiple_attempts :
61+ print ("\n The following libraries required multiple attempts to install:" )
62+ for lib , attempts in multiple_attempts :
63+ print (f"- { lib } (took { attempts } attempts)" )
64+
65+ if not failed_installations and not multiple_attempts :
66+ print ("\n All libraries installed successfully on the first attempt." )
67+ elif not failed_installations :
68+ print ("\n All libraries were eventually installed successfully." )
4569
46- all_files_moved = True
47- for src , dst in files_to_move :
48- if not move_file (src , dst ):
49- all_files_moved = False
70+ return failed_installations , multiple_attempts
5071
51- # Step 4: Print result message
52- if all_files_moved :
72+ def main ():
73+ start_time = time .time ()
74+
75+ # install uv
76+ print ("\033 [92mInstalling uv:\033 [0m" )
77+ subprocess .run (["pip" , "install" , "uv" ], check = True )
78+
79+ print ("\033 [92mInstalling PySide6:\033 [0m" )
80+ subprocess .run (["uv" , "pip" , "install" , "pyside6" , "--no-cache-dir" , "--link-mode=copy" ], check = True )
81+
82+ # Upgrade pip, setuptools, and wheel using uv
83+ print ("\033 [92mUpgrading pip, setuptools, and wheel:\033 [0m" )
84+ subprocess .run (f"{ sys .executable } -m uv pip install --upgrade pip setuptools wheel" , shell = True , check = True )
85+
86+ # Step 2: Install libraries with retry using uv
87+ print ("\033 [92mInstalling dependencies:\033 [0m" )
88+ failed , multiple = install_libraries_with_retry ()
89+
90+ if not failed :
5391 print ("\033 [92mInstallation was successful! The program is ready to use." )
5492 print (f"To run it, enter the command: python ct2_main.py\033 [0m" )
5593 else :
56- print ("\033 [91mInstallation completed with errors. Some files could not be moved." )
57- print ("Please check the error messages above and try to resolve the issues manually.\033 [0m" )
94+ print ("\033 [91mInstallation encountered some issues. Please review the installation summary above.\033 [0m" )
95+
96+ end_time = time .time ()
97+ total_time = end_time - start_time
98+ hours , rem = divmod (total_time , 3600 )
99+ minutes , seconds = divmod (rem , 60 )
100+
101+ print (f"\033 [92m\n Total installation time: { int (hours ):02d} :{ int (minutes ):02d} :{ seconds :05.2f} \033 [0m" )
58102
59103if __name__ == "__main__" :
60104 main ()
0 commit comments