|
|
|
|
| """
|
| PaddlePaddle Auto-Installer
|
| ===========================
|
| This module provides automatic installation and verification of PaddlePaddle
|
| Can be imported or run standalone
|
| """
|
|
|
| import os
|
| import sys
|
| import subprocess
|
| import importlib.util
|
| import time
|
|
|
| def check_paddle_available():
|
| """Check if PaddlePaddle is available"""
|
| try:
|
| import paddle
|
| return True, paddle.__version__
|
| except ImportError:
|
| return False, None
|
|
|
| def install_paddle_emergency():
|
| """Emergency PaddlePaddle installation"""
|
| print("π Emergency PaddlePaddle installation...")
|
| try:
|
|
|
| subprocess.run([
|
| sys.executable, "-m", "pip", "install",
|
| "paddlepaddle==3.1.1", "--timeout", "120", "--no-cache-dir"
|
| ], check=True, timeout=180)
|
| return True
|
| except Exception as e:
|
| print(f"β Emergency install failed: {e}")
|
| return False
|
|
|
| def install_paddle_robust():
|
| """Install using robust installer script"""
|
| script_path = "install_paddle_robust.py"
|
|
|
| if not os.path.exists(script_path):
|
| print(f"β οΈ Robust installer {script_path} not found")
|
| return False
|
|
|
| print(f"π§ Running {script_path}...")
|
| try:
|
| result = subprocess.run([sys.executable, script_path],
|
| capture_output=True, text=True, timeout=300)
|
|
|
| if result.returncode == 0:
|
| print("β
Robust installer completed successfully")
|
| return True
|
| else:
|
| print(f"β Robust installer failed: {result.stderr[:200]}...")
|
| return False
|
| except Exception as e:
|
| print(f"β Error running robust installer: {e}")
|
| return False
|
|
|
| def ensure_paddle_ready():
|
| """Ensure PaddlePaddle is installed and ready"""
|
| print("π Checking PaddlePaddle availability...")
|
|
|
|
|
| available, version = check_paddle_available()
|
| if available:
|
| print(f"β
PaddlePaddle {version} is already available")
|
| return True
|
|
|
| print("β οΈ PaddlePaddle not found, starting installation...")
|
|
|
|
|
| if install_paddle_robust():
|
| available, version = check_paddle_available()
|
| if available:
|
| print(f"β
PaddlePaddle {version} installed via robust installer")
|
| return True
|
|
|
|
|
| if install_paddle_emergency():
|
| available, version = check_paddle_available()
|
| if available:
|
| print(f"β
PaddlePaddle {version} installed via emergency method")
|
| return True
|
|
|
| print("β All installation methods failed")
|
| print("β οΈ PaddlePaddle will not be available")
|
| return False
|
|
|
| def auto_install_on_import():
|
| """Auto-install when this module is imported"""
|
| try:
|
| return ensure_paddle_ready()
|
| except Exception as e:
|
| print(f"β Auto-install failed: {e}")
|
| return False
|
|
|
|
|
| if __name__ != "__main__":
|
|
|
|
|
| auto_install_on_import()
|
|
|
| def main():
|
| """Main function for standalone execution"""
|
| print("=" * 60)
|
| print("π§ PaddlePaddle Auto-Installer")
|
| print("=" * 60)
|
|
|
| success = ensure_paddle_ready()
|
|
|
| if success:
|
| print("\n" + "=" * 60)
|
| print("β
SUCCESS: PaddlePaddle is ready for use!")
|
|
|
|
|
| try:
|
| import paddle
|
| x = paddle.to_tensor([1, 2, 3])
|
| print(f"π§ͺ Basic test passed: {x}")
|
| except Exception as e:
|
| print(f"β οΈ Basic test failed: {e}")
|
|
|
| print("=" * 60)
|
| return True
|
| else:
|
| print("\n" + "=" * 60)
|
| print("β FAILURE: Could not install PaddlePaddle")
|
| print("Please check:")
|
| print("1. Internet connectivity")
|
| print("2. Python and pip installation")
|
| print("3. Available disk space")
|
| print("4. System permissions")
|
| print("=" * 60)
|
| return False
|
|
|
| if __name__ == "__main__":
|
| success = main()
|
| sys.exit(0 if success else 1)
|
|
|