Use uv for Python environment

This commit is contained in:
2026-06-19 18:54:46 +08:00
parent 7083c45feb
commit 87060e30d4
17 changed files with 444 additions and 69 deletions
+28 -4
View File
@@ -13,12 +13,33 @@ scripts/
## 使用场景
### 0. 初始化 Python 环境
项目使用 `uv` 统一管理 Python 虚拟环境,依赖声明在仓库根目录 `pyproject.toml`,锁定版本在 `uv.lock`
```bash
# 如系统尚未安装 uv,先安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# 在仓库根目录执行
cd ~/work/smart-inspection
uv sync
```
`uv sync` 会按 `.python-version` 创建 Python 3.10 虚拟环境到 `.venv`。ROS2 Humble 仍使用系统环境 `/opt/ros/humble`,不要把 ROS2 系统包写入 `pyproject.toml`
系统依赖仍需通过系统包管理器安装:
```bash
sudo apt install -y ffmpeg libzbar0
```
### 1. 首次开机 / 完整重启
```bash
# 在 AGV 上执行
cd ~/work/smart-inspection/scripts
./stop_all.sh # 先彻底清理
./start_all.sh # 完整启动
cd ~/work/smart-inspection
./scripts/stop_all.sh # 先彻底清理
./scripts/start_all.sh # 完整启动
```
### 2. 修改代码后快速部署
@@ -45,7 +66,8 @@ ssh elephant@192.168.60.80 'bash -s' < scripts/start_flask.sh
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `AGV_APP_DIR` | `/home/elephant/work/agv_app` | Flask 项目目录 |
| `AGV_PROJECT_DIR` | `/home/elephant/work/smart-inspection` | 仓库根目录 |
| `AGV_APP_DIR` | `$AGV_PROJECT_DIR/agv_app` | Flask 应用目录 |
| `AGV_ROS2_DIR` | `/home/elephant/agv_pro_ros2` | ROS2 工作空间 |
| `SCAN_FIXER_DIR` | `/home/elephant/work/scan_fixer` | 时间戳修正工具目录 |
| `FIXER_SCRIPT` | `fix_scan_timestamp_v6.py` | fixer 脚本名 |
@@ -64,6 +86,8 @@ ssh elephant@192.168.60.80 'bash -s' < scripts/start_flask.sh
机械臂 (Pi) 的启动由 systemd 托管,在 Pi 上执行:
```bash
cd ~/work/smart-inspection
uv sync
sudo systemctl start arm_server # 启动
sudo systemctl status arm_server # 查看状态
sudo systemctl enable arm_server # 开机自启