- Introduced `check_dependencies.py` to automate dependency checks and provide installation guidance. - Created `install_dependencies.py` for automatic installation of missing dependencies. - Updated `config.json` to include new logging settings for log retention and date-based log file management. - Added `DEPENDENCY_GUIDE.md` and `DEPENDENCY_FIXES_REPORT.md` for comprehensive documentation on dependency management and fixes. - Enhanced logging functionality in `douyin_logging.py` to support date-based log files and automatic cleanup of old logs.
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""自动安装缺失的依赖"""
|
|
|
|
import subprocess
|
|
import sys
|
|
|
|
def install_package(package):
|
|
"""安装指定的包"""
|
|
try:
|
|
print(f"Installing {package}...")
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
|
print(f"[SUCCESS] {package} installed successfully")
|
|
return True
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"[ERROR] Failed to install {package}: {e}")
|
|
return False
|
|
|
|
def main():
|
|
# 检查缺失的依赖
|
|
missing = []
|
|
|
|
try:
|
|
import paddlepaddle
|
|
except ImportError:
|
|
missing.append("paddlepaddle>=2.5.0,<3.0.0")
|
|
|
|
try:
|
|
import ttkbootstrap
|
|
except ImportError:
|
|
missing.append("ttkbootstrap>=1.10.0")
|
|
|
|
if not missing:
|
|
print("[SUCCESS] All dependencies are installed!")
|
|
return 0
|
|
|
|
print(f"Missing dependencies: {', '.join(missing)}")
|
|
print("\nDo you want to install them? (y/n): ", end='')
|
|
|
|
# 在非交互环境中自动安装
|
|
response = 'y'
|
|
try:
|
|
response = input().strip().lower()
|
|
except (EOFError, KeyboardInterrupt):
|
|
response = 'y' # 默认安装
|
|
|
|
if response in ('y', 'yes', ''):
|
|
success_count = 0
|
|
for pkg in missing:
|
|
if install_package(pkg):
|
|
success_count += 1
|
|
|
|
if success_count == len(missing):
|
|
print("\n[SUCCESS] All dependencies installed successfully!")
|
|
return 0
|
|
else:
|
|
print(f"\n[WARNING] {len(missing) - success_count} package(s) failed to install")
|
|
print("You may need to install them manually:")
|
|
print(f"pip install {' '.join(missing)}")
|
|
return 1
|
|
else:
|
|
print("Installation cancelled.")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|
|
|