forked from ArdianaLeek/VodRecovery
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
install_dependencies.py
57 lines (43 loc) · 1.95 KB
/
install_dependencies.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
import os
from importlib import import_module
import subprocess
import sys
def install_requirements(requirements_path):
with open(requirements_path, encoding='utf-8') as f:
packages = f.read().splitlines()
for package in packages:
if not check_package(package):
try:
print(f"Installing {package}...")
subprocess.run([sys.executable, "-m", "pip", "install", package, "-q", "--no-warn-conflicts"], check=True)
except subprocess.CalledProcessError:
# Install latest version
print(f"\n\033[34mFailed to install {package}. Trying again...\033[0m")
print(f"Installing {package.split('==')[0]}...")
subprocess.run([sys.executable, "-m", "pip", "install", package.split('==')[0], "-q", "--no-warn-conflicts"], check=True)
def check_package(package_name):
try:
import_module(package_name)
return True
except ImportError:
return False
def update_pip():
try:
subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "pip", "-q"],
capture_output=True, check=False)
except Exception as e:
print(f"Error updating pip: {str(e)}")
if __name__ == "__main__":
try:
print("Installing dependencies...")
update_pip()
script_dir = os.path.dirname(os.path.abspath(__file__))
requirements_file = os.path.join(script_dir, 'lib', 'requirements.txt')
install_ffmpeg_script = os.path.join(script_dir, 'lib', 'install_ffmpeg.py')
vod_recovery_script = os.path.join(script_dir, 'vod_recovery.py')
install_requirements(requirements_file)
subprocess.run([sys.executable, install_ffmpeg_script], check=False)
subprocess.run([sys.executable, vod_recovery_script], check=False)
except Exception as e:
print(f"An error occurred: {str(e)}")
input("\nPress Enter to continue...")