58 lines
1.8 KiB
Python
Executable File
58 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
|
|
def run_command(command, shell=False):
|
|
"""运行命令并返回结果"""
|
|
try:
|
|
result = subprocess.run(command, shell=shell, check=True,
|
|
capture_output=True, text=True)
|
|
return result.returncode, result.stdout, result.stderr
|
|
except subprocess.CalledProcessError as e:
|
|
return e.returncode, e.stdout, e.stderr
|
|
|
|
def main():
|
|
print("启动YOLO应用...")
|
|
|
|
# 检查虚拟环境是否存在
|
|
if not os.path.exists("venv"):
|
|
print("❌ 错误: 虚拟环境不存在!")
|
|
print("请先运行 python3 setup_and_run.py 来创建环境和安装依赖")
|
|
sys.exit(1)
|
|
|
|
# 确定虚拟环境中的Python解释器路径
|
|
if os.name == 'nt': # Windows
|
|
venv_python = os.path.join("venv", "Scripts", "python.exe")
|
|
else: # macOS/Linux
|
|
venv_python = os.path.join("venv", "bin", "python")
|
|
|
|
# 检查虚拟环境的Python是否存在
|
|
if not os.path.exists(venv_python):
|
|
print("❌ 错误: 虚拟环境损坏!")
|
|
print("请重新创建虚拟环境")
|
|
sys.exit(1)
|
|
|
|
# 检查测试视频文件是否存在
|
|
if not os.path.exists("res/test.mp4"):
|
|
print("❌ 错误: res/test.mp4 文件不存在!")
|
|
print("请在 res/ 目录中放置名为 test.mp4 的视频文件")
|
|
sys.exit(1)
|
|
|
|
print("✅ 找到测试视频文件: res/test.mp4")
|
|
|
|
# 运行应用
|
|
print("运行应用...")
|
|
os.chdir("src")
|
|
returncode, stdout, stderr = run_command([os.path.join("..", venv_python), "app.py"])
|
|
|
|
if returncode == 0:
|
|
print("✅ 应用运行完成!")
|
|
else:
|
|
print(f"❌ 应用运行失败: {stderr}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main() |