-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrun.py
More file actions
96 lines (80 loc) · 2.62 KB
/
run.py
File metadata and controls
96 lines (80 loc) · 2.62 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
QLib因子分析平台启动脚本
"""
import os
import sys
import subprocess
from pathlib import Path
def check_dependencies():
"""检查依赖包"""
required_packages = [
'streamlit', 'pandas', 'numpy', 'plotly', 'qlib'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
except ImportError:
missing_packages.append(package)
if missing_packages:
print("❌ 缺少以下依赖包:")
for package in missing_packages:
print(f" - {package}")
print("\n请运行以下命令安装依赖:")
print("pip install -r requirements.txt")
return False
print("✅ 所有依赖包已安装")
return True
def check_qlib_data():
"""检查QLib数据"""
qlib_data_path = Path.home() / ".qlib" / "qlib_data" / "cn_data"
if not qlib_data_path.exists():
print("⚠️ QLib数据不存在")
print("正在下载QLib数据...")
try:
import qlib
from qlib.constant import REG_CN
from qlib.tests.data import GetData
GetData().qlib_data(target_dir=str(qlib_data_path), region=REG_CN)
print("✅ QLib数据下载完成")
return True
except Exception as e:
print(f"❌ QLib数据下载失败: {e}")
return False
else:
print("✅ QLib数据已就绪")
return True
def main():
"""主函数"""
print("🚀 QLib因子分析平台启动检查")
print("=" * 50)
# 检查依赖
if not check_dependencies():
sys.exit(1)
# 检查QLib数据
if not check_qlib_data():
print("⚠️ 继续启动应用,但某些功能可能不可用")
print("\n🎯 启动Streamlit应用...")
print("应用将在浏览器中打开: http://localhost:8501")
print("按 Ctrl+C 停止应用")
print("=" * 50)
try:
# 启动Streamlit应用
subprocess.run([
sys.executable, "-m", "streamlit", "run", "app.py",
"--server.port", "8501",
"--server.address", "localhost",
"--browser.gatherUsageStats", "false"
], check=True)
except KeyboardInterrupt:
print("\n👋 应用已停止")
except subprocess.CalledProcessError as e:
print(f"❌ 启动失败: {e}")
sys.exit(1)
except FileNotFoundError:
print("❌ 未找到streamlit命令,请确保已正确安装")
sys.exit(1)
if __name__ == "__main__":
main()