Files
mkdocs/docs/Obsidian笔记体系/Projects/aitsc/wk3 Windows 运行.md
2026-05-11 00:31:26 +08:00

5.6 KiB
Raw Blame History

✅ 完全支持 Windows 运行

aitsc 项目完全支持在 Windows 系统上运行,并且提供了多种运行方式,从开发环境到生产部署都有完整支持。

🚀 支持的运行方式

  1. 开发环境运行(最简单)

激活虚拟环境(推荐)

.venv\Scripts\Activate.bat

启动开发服务器

python run_dev.py

  1. 生产环境运行

使用生产启动脚本

start_production.bat

或

python run_production_public.py

  • 关闭调试模式,优化性能
  • 监听所有网络接口(支持外网访问)
  • 多线程处理请求
  1. Windows 系统服务(推荐用于生产)

以管理员身份运行安装脚本

install_service.bat

或手动安装服务

python flask_prompt_master_service.py install python flask_prompt_master_service.py start

  • 支持开机自启动
  • 后台运行,无需保持命令行窗口
  • 作为系统服务管理(启动/停止/重启)
  1. 简化版开机启动

使用任务计划程序实现开机启动

python simple_windows_service.py install

  • 基于 Windows 任务计划程序
  • 系统启动时自动运行
  • 不需要完整服务框架

📋 Windows 运行前提条件

  1. Python 环境
  • Python 3.12(推荐)
  • 已安装 pip
  1. 虚拟环境(推荐)

创建虚拟环境

python -m venv .venv

激活虚拟环境

.venv\Scripts\Activate.bat

  1. 安装依赖

pip install -r requirements.txt 关键 Windows 依赖:

  • pywin32 - Windows API 接口(服务部署必需)
  • waitress - WSGI 服务器
  • bcrypt - 密码哈希(已升级安全算法)

🔧 Windows 特定配置

  1. 环境变量配置
  • 复制 .env.example 为 .env
  • 编辑 .env 文件,配置数据库连接等参数
  • 注意:Windows 路径使用反斜杠或双反斜杠
  1. 端口配置
  • 默认端口:5002(开发)/ 5000(服务)
  • 如果端口冲突,可在 .env 中修改 PORT 变量
  1. 防火墙配置

允许端口通过防火墙

New-NetFirewallRule -DisplayName "FlaskPromptMaster" -Direction Inbound -LocalPort 5000 -Protocol TCP -Action Allow

📁 关键 Windows 文件

aitsc/ ├── install_service.bat # 服务安装脚本(管理员运行) ├── install_startup.bat # 开机启动安装脚本 ├── service_manager.bat # 服务管理脚本(图形菜单) ├── simple_service_manager.bat # 简化版服务管理 ├── start_production.bat # 生产环境启动脚本 ├── flask_prompt_master_service.py # 完整 Windows 服务脚本 ├── simple_windows_service.py # 简化版服务脚本 └── docs/development/ └── Windows服务配置总结.md # 详细配置指南

⚡ 快速开始指南

方案一:开发测试

1. 安装依赖

pip install -r requirements.txt

2. 配置环境变量

copy .env.example .env

编辑 .env 文件(数据库、API密钥等)

3. 启动开发服务器

python run_dev.py

方案二:生产部署

1. 安装依赖和服务组件

pip install -r requirements.txt

2. 安装 Windows 服务

install_service.bat

或右键"以管理员身份运行"

3. 服务会自动启动,开机自启动

访问 http://localhost:5000

🛠️ 故障排除

┌──────────────────┬──────────────────────────────────────────┐ │ 问题 │ 解决方案 │ ├──────────────────┼──────────────────────────────────────────┤ │ 权限不足 │ 右键脚本 → "以管理员身份运行" │ ├──────────────────┼──────────────────────────────────────────┤ │ 端口冲突 │ 修改 .env 中的 PORT 变量 │ ├──────────────────┼──────────────────────────────────────────┤ │ pywin32 安装失败 │ 使用预编译版本:pip install pywin32==306 │ ├──────────────────┼──────────────────────────────────────────┤ │ 虚拟环境激活失败 │ 确认 Python 路径正确:where python │ ├──────────────────┼──────────────────────────────────────────┤ │ 服务启动失败 │ 查看日志:logs\service.log │ └──────────────────┴──────────────────────────────────────────┘

🎯 推荐方案

个人使用/开发 → 使用 run_dev.py(简单快捷)

小型部署 → 使用 simple_windows_service.py + 开机启动

企业级部署 → 使用完整的 Windows 服务 (install_service.bat)

总结:aitsc 在 Windows 上的支持非常完善,既有简单的开发运行方式,也有专业的 Windows 服务部署方案,完全可以满足从开发到生产的全链路需求。