-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.py
More file actions
40 lines (29 loc) · 892 Bytes
/
start.py
File metadata and controls
40 lines (29 loc) · 892 Bytes
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
"""
Windows 启动脚本 — 创建虚拟环境并启动服务
"""
import subprocess
import sys
import os
from pathlib import Path
ROOT = Path(__file__).parent
VENV = ROOT / ".venv"
def ensure_venv():
"""确保虚拟环境存在"""
if not VENV.exists():
print(f"创建虚拟环境: {VENV}")
subprocess.run([sys.executable, "-m", "venv", str(VENV)], check=True)
pip = VENV / "Scripts" / "pip.exe"
if not pip.exists():
pip = VENV / "bin" / "pip"
print("安装依赖...")
subprocess.run([str(pip), "install", "-r", str(ROOT / "requirements.txt")], check=True)
def start():
"""启动服务"""
ensure_venv()
python = VENV / "Scripts" / "python.exe"
if not python.exists():
python = VENV / "bin" / "python"
os.chdir(str(ROOT))
subprocess.run([str(python), "main.py"])
if __name__ == "__main__":
start()