运行环境搭建
这一步做完的标志是:终端里敲 lerobot-teleoperate --help 能打出帮助信息。顺序别调——先换源,再下载,整个流程才不会被超时反复打断。
2.1 安装 conda
Mac 用 Miniforge(Apple Silicon 用 arm64 版):
bash
# 官方地址;国内慢的话换清华 github-release 镜像下的同名文件
curl -L -O \
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
bash Miniforge3-MacOSX-arm64.sh
# 装完重开一个终端,确认可用
conda --version2.2 配置镜像源
先把下载通道修好,后面几步才不会卡。pip:
bash
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/写入 ~/.config/pip/pip.conf,对所有 Python 环境生效,之后装包不用再带 -i。
conda 也换掉,否则装 ffmpeg 会卡在 repo.anaconda.com:
bash
conda config --set channel_alias https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
conda config --add default_channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add default_channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --set show_channel_urls true2.3 创建虚拟环境
LeRobot 要求 Python 3.10,单独建一个环境,别污染系统 Python:
bash
conda create -y -n lerobot python=3.10
conda activate lerobot
# 激活后命令行前面会出现 (lerobot),确认一下 Python 版本
python --version2.4 获取源码
直连 GitHub 在国内很慢,用 gitclone.com 做前缀,克隆完成后进入仓库目录:
bash
# 本项目用的是第三方 fork:JoyandAI/lerobot
git clone https://gitclone.com/github.com/JoyandAI/lerobot.git ~/lerobot
cd ~/lerobot也可以配一次全局替换,之后所有 GitHub 地址自动走镜像:
bash
git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/"注意:
JoyandAI/lerobot是第三方 fork,装依赖以它自己的 README 为准。
2.5 安装 ffmpeg 与 LeRobot
ffmpeg 由 conda 提供(LeRobot 用它做视频编解码):
bash
conda install -y ffmpeg -c conda-forge
# 装 LeRobot,带上 Feetech 舵机支持;-e 是源码可编辑安装
cd ~/lerobot
pip install -e ".[feetech]"Mac 上还有个更省事的选择:brew install ffmpeg 直接用系统 ffmpeg,绕开 conda 这一步。
2.6 安装验证
bash
python -c "import torch, lerobot; print('lerobot ok')"
lerobot-teleoperate --help
# 顺便看一眼算力后端:Mac 上这里必然打印 False,正常
python -c "import torch; print('cuda =', torch.cuda.is_available())"验证:能打印
lerobot ok、并且lerobot-teleoperate --help有输出,环境就算通了。cuda = False在 Mac 上是预期结果,训练放云端解决。
2.7 把 LeRobot 更新到最新
这个库接口改得很快,官方文档、社区教程和你本地这份代码经常不在同一个版本上。要跟仓库同步时,先在本地改过的地方要暂存,再拉取:
bash
cd ~/lerobot
git stash # ① 先把本地修改收起来
git pull # ② 拉最新代码
git stash pop # ③ 把修改放回来(有冲突会提示,手动解决)- 本项目是
pip install -e装的,代码更新完不用重装,直接生效。 - 如果
pyproject.toml也有改动(依赖清单变了),补一句pip install -e ".[feetech]"。 - 更新后至少验证三件事:
lerobot-teleoperate --help能跑、校准能连上、录制命令参数没被改名。 - **更稳的做法是先在当前版本上把整条链路跑通,再考虑升级。**升级出问题就用
git log找到上一个能用的提交,git checkout <sha>退回去。