trading.ai/install_mysql_deps.py
2025-09-23 16:12:18 +08:00

65 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
安装MySQL依赖包
"""
import subprocess
import sys
from loguru import logger
def install_mysql_dependencies():
"""安装MySQL相关依赖"""
logger.info("📦 开始安装MySQL依赖包...")
packages = [
'pymysql', # MySQL数据库连接器
'cryptography', # 加密支持
'sqlalchemy', # SQL工具包可选
]
for package in packages:
try:
logger.info(f"📥 安装 {package}...")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
logger.info(f"{package} 安装成功")
except subprocess.CalledProcessError as e:
logger.error(f"{package} 安装失败: {e}")
return False
# 验证安装
try:
import pymysql
logger.info("✅ pymysql 导入成功")
import cryptography
logger.info("✅ cryptography 导入成功")
logger.info("🎉 所有MySQL依赖安装完成!")
return True
except ImportError as e:
logger.error(f"❌ 依赖验证失败: {e}")
return False
def main():
"""主函数"""
success = install_mysql_dependencies()
if success:
print("\n" + "="*50)
print("🎉 MySQL依赖安装完成!")
print("="*50)
print("\n📝 下一步:")
print("1. 运行数据迁移: python migrate_to_mysql.py")
print("2. 启动MySQL版Web服务: python web/mysql_app.py")
print("3. 访问: http://localhost:8080")
else:
print("\n❌ MySQL依赖安装失败请检查网络连接和权限")
sys.exit(1)
if __name__ == "__main__":
main()