# 内网离线移植步骤 ## 1. 迁移原则 不要直接拷贝现有 `.venv` 到内网服务器。Ubuntu 20.04 默认 Python 版本偏低,而本项目要求 `python >= 3.10`,且虚拟环境对路径和系统 ABI 敏感。推荐迁移“项目源代码 + `uv.lock` + 离线 wheel 包 + Python 运行时”。 ## 2. 在线准备机打包 在一台可联网机器上完成一次完整解析与下载: ```bash uv sync uv export --frozen --no-dev -o requirements.txt uv pip download -r requirements.txt -d wheelhouse ``` 同时打包以下内容: - `app/` - `scripts/` - `tests/` - `GJB438C-2021_prd_skills/` - `configs/` - `pyproject.toml` - `uv.lock` - `requirements.txt` - `wheelhouse/` - `uv` 可执行文件(Linux x86_64) 如果目标机没有 Python 3.10+,还要额外准备一个可移植的 Python 3.10/3.12 运行时目录。 ## 3. 目标机落地 将打包内容拷贝到 Ubuntu 20.04 内网服务器,例如 `/opt/docx-analyzer`。 ```bash cd /opt/docx-analyzer chmod +x uv ``` 如果系统已有 Python 3.10+: ```bash UV_CACHE_DIR=/opt/docx-analyzer/.uv-cache ./uv sync --frozen --offline ``` 如果系统没有满足版本的 Python: ```bash ./uv venv .venv --python /opt/python/bin/python3.12 UV_CACHE_DIR=/opt/docx-analyzer/.uv-cache ./uv sync --frozen --offline ``` ## 4. 启动与验证 启动服务: ```bash UV_CACHE_DIR=/opt/docx-analyzer/.uv-cache ./uv run uvicorn app.main:app --host 0.0.0.0 --port 8010 ``` 验证命令: ```bash UV_CACHE_DIR=/opt/docx-analyzer/.uv-cache ./uv run pytest curl http://127.0.0.1:8010/ ``` 分析样例文件时,确认 `configs/api_config.yaml` 中的 `intranet` 配置指向内网模型地址,且网络可访问。 ## 5. 运维建议 - 用 `systemd` 把 `uvicorn` 注册成服务。 - 把 `uploads/`、`outputs/`、`.uv-cache/` 放在独立目录并定期清理。 - 首次上线先用 `use_model=false` 验证本地流程,再切到 `intranet` 模型。