-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
98 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,104 @@ | ||
import subprocess | ||
import sys | ||
import os | ||
import time | ||
from pathlib import Path | ||
import shutil | ||
|
||
def run_command(command): | ||
try: | ||
subprocess.run(command, shell=True, check=True) | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error running command: {command}") | ||
print(f"Error message: {e}") | ||
sys.exit(1) | ||
|
||
def move_file(src, dst): | ||
try: | ||
if not src.exists(): | ||
print(f"Source file not found: {src}") | ||
return False | ||
shutil.move(str(src), str(dst)) | ||
print(f"Moved {src.name} to {dst}") | ||
return True | ||
except PermissionError: | ||
print(f"Permission denied when trying to move {src}") | ||
except Exception as e: | ||
print(f"Error moving {src}: {e}") | ||
return False | ||
|
||
def main(): | ||
# Step 1: Upgrade pip, setuptools, and wheel | ||
run_command("python -m pip install --upgrade pip setuptools wheel") | ||
def install_libraries_with_retry(max_retries=3, delay=3): | ||
libraries = [ | ||
"av==12.3.0", | ||
"CFFI==1.16.0", | ||
"certifi==2024.7.4", | ||
"chardet==5.2.0", | ||
"ctranslate2==4.3.1", | ||
"faster-whisper==1.0.2", | ||
"filelock==3.15.4", | ||
"huggingface-hub==0.24.1", | ||
"idna==3.7", | ||
"nvidia-cublas-cu12==12.1.3.1", | ||
"nvidia-cuda-nvrtc-cu12==12.1.105", | ||
"nvidia-cuda-runtime-cu12==12.1.105", | ||
"nvidia-cudnn-cu12==8.9.7.29", | ||
"numpy==1.26.4", | ||
"pycparser==2.22", | ||
"PyYAML==6.0.1", | ||
"requests==2.32.3", | ||
"sounddevice==0.4.7", | ||
"tokenizers==0.19.1", | ||
"tqdm==4.66.4", | ||
"urllib3==2.2.2" | ||
] | ||
|
||
# Step 2: Install requirements | ||
run_command("pip install -r requirements.txt") | ||
failed_installations = [] | ||
multiple_attempts = [] | ||
|
||
# Step 3: Move files | ||
current_dir = Path(__file__).parent.resolve() | ||
python_lib_path = current_dir / 'Lib' / 'site-packages' | ||
for library in libraries: | ||
for attempt in range(max_retries): | ||
try: | ||
print(f"\nAttempt {attempt + 1} of {max_retries}: Installing {library}") | ||
command = [sys.executable, "-m", "uv", "pip", "install", library, "--no-deps", "--no-cache-dir"] | ||
subprocess.run(command, check=True, capture_output=True, text=True) | ||
print(f"Successfully installed {library}") | ||
if attempt > 0: | ||
multiple_attempts.append((library, attempt + 1)) | ||
break | ||
except subprocess.CalledProcessError as e: | ||
print(f"Attempt {attempt + 1} failed. Error: {e.stderr.strip()}") | ||
if attempt < max_retries - 1: | ||
print(f"Retrying in {delay} seconds...") | ||
time.sleep(delay) | ||
else: | ||
print(f"Failed to install {library} after {max_retries} attempts.") | ||
failed_installations.append(library) | ||
|
||
files_to_move = [ | ||
(python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublas64_12.dll', current_dir), | ||
(python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublasLt64_12.dll', current_dir), | ||
(python_lib_path / 'nvidia' / 'cudnn' / 'bin' / 'cudnn_cnn_infer64_8.dll', current_dir) | ||
] | ||
print("\n--- Installation Summary ---") | ||
if failed_installations: | ||
print("\nThe following libraries failed to install:") | ||
for lib in failed_installations: | ||
print(f"- {lib}") | ||
|
||
if multiple_attempts: | ||
print("\nThe following libraries required multiple attempts to install:") | ||
for lib, attempts in multiple_attempts: | ||
print(f"- {lib} (took {attempts} attempts)") | ||
|
||
if not failed_installations and not multiple_attempts: | ||
print("\nAll libraries installed successfully on the first attempt.") | ||
elif not failed_installations: | ||
print("\nAll libraries were eventually installed successfully.") | ||
|
||
all_files_moved = True | ||
for src, dst in files_to_move: | ||
if not move_file(src, dst): | ||
all_files_moved = False | ||
return failed_installations, multiple_attempts | ||
|
||
# Step 4: Print result message | ||
if all_files_moved: | ||
def main(): | ||
start_time = time.time() | ||
|
||
# install uv | ||
print("\033[92mInstalling uv:\033[0m") | ||
subprocess.run(["pip", "install", "uv"], check=True) | ||
|
||
print("\033[92mInstalling PySide6:\033[0m") | ||
subprocess.run(["uv", "pip", "install", "pyside6", "--no-cache-dir", "--link-mode=copy"], check=True) | ||
|
||
# Upgrade pip, setuptools, and wheel using uv | ||
print("\033[92mUpgrading pip, setuptools, and wheel:\033[0m") | ||
subprocess.run(f"{sys.executable} -m uv pip install --upgrade pip setuptools wheel", shell=True, check=True) | ||
|
||
# Step 2: Install libraries with retry using uv | ||
print("\033[92mInstalling dependencies:\033[0m") | ||
failed, multiple = install_libraries_with_retry() | ||
|
||
if not failed: | ||
print("\033[92mInstallation was successful! The program is ready to use.") | ||
print(f"To run it, enter the command: python ct2_main.py\033[0m") | ||
else: | ||
print("\033[91mInstallation completed with errors. Some files could not be moved.") | ||
print("Please check the error messages above and try to resolve the issues manually.\033[0m") | ||
print("\033[91mInstallation encountered some issues. Please review the installation summary above.\033[0m") | ||
|
||
end_time = time.time() | ||
total_time = end_time - start_time | ||
hours, rem = divmod(total_time, 3600) | ||
minutes, seconds = divmod(rem, 60) | ||
|
||
print(f"\033[92m\nTotal installation time: {int(hours):02d}:{int(minutes):02d}:{seconds:05.2f}\033[0m") | ||
|
||
if __name__ == "__main__": | ||
main() |