diff --git a/python_core/ai_video/video_generator.py b/python_core/ai_video/video_generator.py index 0c3d615..8e02a88 100644 --- a/python_core/ai_video/video_generator.py +++ b/python_core/ai_video/video_generator.py @@ -14,6 +14,15 @@ from typing import Dict, Any, List, Optional, Callable import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +# Add startup logging +print("=== AI Video Generator Starting ===") +print(f"Python version: {sys.version}") +print(f"Working directory: {os.getcwd()}") +print(f"Script path: {__file__}") +print(f"Arguments: {sys.argv}") +print("=====================================") +sys.stdout.flush() + try: from config import settings from utils import setup_logger @@ -29,11 +38,22 @@ try: from .cloud_storage import CloudStorage from .api_client import APIClient from .jsonrpc import create_response_handler, create_progress_reporter, JSONRPCError -except ImportError: - # Fallback for when running as script - from cloud_storage import CloudStorage - from api_client import APIClient - from jsonrpc import create_response_handler, create_progress_reporter, JSONRPCError + print("Successfully imported local modules") +except ImportError as e: + print(f"Import error with relative imports: {e}") + try: + # Fallback for when running as script + from cloud_storage import CloudStorage + from api_client import APIClient + from jsonrpc import create_response_handler, create_progress_reporter, JSONRPCError + print("Successfully imported modules with direct imports") + except ImportError as e2: + print(f"CRITICAL ERROR: Failed to import required modules: {e2}") + print("Python path:", sys.path) + print("Current directory contents:", os.listdir(".")) + print("Module directory contents:", os.listdir(os.path.dirname(__file__))) + sys.stdout.flush() + sys.exit(1) logger = setup_logger(__name__) diff --git a/src-tauri/src/commands/ai_video.rs b/src-tauri/src/commands/ai_video.rs index 52d81e3..051c74a 100644 --- a/src-tauri/src/commands/ai_video.rs +++ b/src-tauri/src/commands/ai_video.rs @@ -37,22 +37,41 @@ async fn execute_python_command(_app: tauri::AppHandle, args: &[String]) -> Resu println!("Working directory: {:?}", project_root); - // Try python3 first, then python (for Windows compatibility) - let python_cmd = if cfg!(target_os = "windows") { - "python" + // Try multiple Python commands in order of preference + let python_commands = if cfg!(target_os = "windows") { + vec!["python", "python3", "py"] } else { - "python3" + vec!["python3", "python"] }; - let mut cmd = Command::new(python_cmd); - cmd.current_dir(&project_root); - cmd.args(args); - cmd.stdout(std::process::Stdio::piped()); - cmd.stderr(std::process::Stdio::piped()); + let mut child = None; + let mut last_error = String::new(); - println!("Starting Python process..."); - let mut child = cmd.spawn() - .map_err(|e| format!("Failed to start Python process: {}", e))?; + for python_cmd in python_commands { + println!("Trying Python command: {}", python_cmd); + let mut cmd = Command::new(python_cmd); + cmd.current_dir(&project_root); + cmd.args(args); + cmd.stdout(std::process::Stdio::piped()); + cmd.stderr(std::process::Stdio::piped()); + + match cmd.spawn() { + Ok(process) => { + println!("Successfully started Python process with: {}", python_cmd); + child = Some(process); + break; + } + Err(e) => { + last_error = format!("Failed to start {} process: {}", python_cmd, e); + println!("{}", last_error); + continue; + } + } + } + + let mut child = child.ok_or_else(|| { + format!("Failed to start Python process with any command. Last error: {}", last_error) + })?; let stdout = child.stdout.take().unwrap(); let stderr = child.stderr.take().unwrap(); @@ -196,24 +215,37 @@ pub async fn test_ai_video_environment(_app: tauri::AppHandle) -> Result { + if output.status.success() { + let stdout = String::from_utf8_lossy(&output.stdout); + return Ok(format!("Environment test passed with {}:\n{}", python_cmd, stdout)); + } else { + let stderr = String::from_utf8_lossy(&output.stderr); + println!("Python {} test failed: {}", python_cmd, stderr); + continue; + } + } + Err(e) => { + println!("Failed to execute Python {}: {}", python_cmd, e); + continue; + } + } } + + Err("Failed to find a working Python installation".to_string()) }