mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 12:19:32 +08:00
python-runtime 与 dev-environment-setup 还在描述客户端 10.0.105 之前的 Hatch 布局:正常安装时没有 runtime/hatch/hatch,probe-python.sh 的 hatch_path 恒空,Agent 接着就会用系统包管理器。文档的 CLI 写法同样有问题:Hatch 1.16.5 里没有 HATCH_HOME 和 HATCH_PYTHON_MIRROR_URL,不带 --private --dir 的 python install 装到用户数据目录并改写 .zshrc、.zprofile,DesireCore 也看不到那个 Python。 - 二进制改为随包的 static/toolchains/<平台>-<架构>/hatch/hatch;runtime/hatch/hatch 只有手动下载后才存在 - 先用已在 PATH 上的内置 Python;指定版本用 runtime/hatch/local/<版本> 的绝对路径,pip 走探测到的解释器 - 安装命令带 --private --dir,环境变量改为 PYAPP_INSTALL_DIR_HATCH;换下载源用 HATCH_PYTHON_CUSTOM_SOURCE_<NAME>,并写明 URL 形态约束 - probe-python.sh 按新布局查找,新增 hatch_bootstrap,只认与二进制同版本的分发;没有解包好的分发时不执行二进制,避免 --version 触发下载;输出的路径字段做 JSON 转义 - 写明这个 bash 探测脚本在 Windows 上不查找 Hatch,降级到 L3 前先试 L2 的 Windows 路径 - 记录首启导入把本机镜像地址写进 hatch-dist.json,导致 local/ 上的 Hatch 命令报 Unknown distribution source,并给出修复办法;客户端修复见 desirecore/desirecore#5578 - desirecore-runtime.md 的源码路径改为 packages/agent-service/src;decision-tree.md 补上 standalone 的 401 - 版本 python-runtime 1.0.3 → 1.0.4、dev-environment-setup 2.0.5 → 2.0.6,sidecar 与 i18n source_hash 同步;不设客户端版本门槛 Correct the Hatch paths and install commands in python-runtime and dev-environment-setup, which still described the layout from before client 10.0.105 and told Agents to run an install that edits shell startup files and lands where DesireCore cannot see it. probe-python.sh now finds the current layout, reports the unpacked distribution, and no longer triggers a download. 验证:catalog metadata 与 i18n 校验 0 error,translate --check 通过,market-i18n-real-repo 22/22;真实 Hatch 1.16.5 在隔离 HOME 下逐条跑过文档命令;standalone 隔离 HOME + mock 模型下真实 Bash 工具按文档跑通,未调用真实模型;探测脚本覆盖多种布局及含引号、反斜杠的路径。Windows 写法只对照源码。私有敏感词扫描未执行,经用户确认后合并。
4.6 KiB
4.6 KiB
Python 故障排查
"python: command not found" / "python3: command not found"
原因:未安装或未加入 PATH。
# 1. 找一下二进制
which python3 2>/dev/null; which python 2>/dev/null
ls /usr/bin/python* /usr/local/bin/python* /opt/homebrew/bin/python* 2>/dev/null
ls "${DESIRECORE_ROOT}"/runtime/hatch/local/*/python/bin/python3 2>/dev/null # DesireCore 内置
# 2. 查 PATH
echo "$PATH" | tr ':' '\n' | head -20
# 3. macOS:检查 Homebrew Python
brew list python 2>/dev/null && echo "Homebrew Python installed"
# 4. 修复 PATH
# Apple Silicon
export PATH="/opt/homebrew/bin:$PATH"
# Intel mac / Linux 常见
export PATH="/usr/local/bin:$PATH"
根治:按主 SKILL.md 决策树重新执行 L1–L3 安装路径。
"pip: command not found"
# 用 module 模式调用
python3 -m pip --version
# 仍失败:手动 bootstrap
curl -fsSL https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
python3 /tmp/get-pip.py --user
rm /tmp/get-pip.py
# 把 ~/.local/bin 加入 PATH(zsh / bash)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
"externally-managed-environment"(PEP 668)
触发系统:Debian 12+、Ubuntu 23.04+、Fedora 38+、Arch(部分)。
优先级从高到低:
# 方案 1(推荐):虚拟环境
python3 -m venv .venv
source .venv/bin/activate
pip install package-name
# 方案 2:pipx 装 CLI 工具
pipx install package-name
# 方案 3:用户目录
pip install --user package-name
# 方案 4(不推荐,可能破坏系统)
pip install --break-system-packages package-name
SSL / TLS 证书错误
# pip:升级 certifi
pip install --upgrade certifi
# 临时绕过(仅调试)
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org package-name
# 永久信任(不推荐)
pip config set global.trusted-host "pypi.org files.pythonhosted.org"
macOS 系统时间偏差也会导致 SSL 失败:sudo sntp -sS time.apple.com。
import 失败
包名 ≠ import 名是最常见原因:
| 安装名 (pip install) | import 名 |
|---|---|
| Pillow | PIL |
| python-dateutil | dateutil |
| beautifulsoup4 | bs4 |
| scikit-learn | sklearn |
| PyYAML | yaml |
| pytorch | torch |
# 1. 确认安装到了正确的 Python
python3 -c "import sys; print(sys.executable)"
pip3 show package-name
# 2. 是否在虚拟环境
echo "$VIRTUAL_ENV"
# 3. 强制重装
pip install --force-reinstall --no-cache-dir package-name
macOS "xcrun: error" / 编译失败
安装 lxml / numpy / Pillow 等需要 C 扩展的包时:
# 安装 / 重置 Xcode CLI
xcode-select --install
sudo xcode-select --reset
# 包级依赖
brew install libxml2 libxslt # lxml
brew install libjpeg zlib # Pillow
brew install openssl readline # cryptography 类
Windows PowerShell 执行策略
Get-ExecutionPolicy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
之后才能 .\.venv\Scripts\Activate.ps1。
Windows Store 占位符
python --version 弹出 Store 页面:
- 设置 → 应用 → 高级应用设置 → 应用执行别名
- 关闭
python.exe/python3.exe的 Store 别名 - 重启终端
代理环境配置
# pip
pip install --proxy http://proxy:port package-name
pip config set global.proxy http://proxy:port
# 取消
pip config unset global.proxy
# 系统级(zsh / bash)
export http_proxy=http://proxy:port
export https_proxy=http://proxy:port
EnvironmentSnapshot 信号速查
probe-python.sh 输出后,按字段快速判断:
| 字段 | 期望 | 失败原因 |
|---|---|---|
system_python.version |
非空且 ≥ 3.8 | 未装 Python 或版本太低 |
system_pip.version |
非空 | pip 未装(macOS Apple 自带 Python 没有 pip) |
hatch_path |
非空 | 没找到 DesireCore Hatch,通常是应用装在非默认位置。走 L1,见 hatch-desirecore.md 的「找不到 Hatch 二进制」 |
hatch_bootstrap |
非空 | Hatch 分发解包还没完成或客户端早于 10.0.183,直接调用会先联网下载,见 hatch-desirecore.md |
pep668: true |
— | 系统 Python 受保护,必须 venv/pipx |
active_venv |
操作前为空,激活后非空 | venv 未生效,重新 source .venv/bin/activate |
重置整个 Python 环境(最后手段)
# 1. 退出所有虚拟环境
deactivate 2>/dev/null
conda deactivate 2>/dev/null
# 2. 删除可疑虚拟环境
rm -rf .venv venv
# 3. 重新探测
bash skills/python-runtime/scripts/probe-python.sh
# 4. 按主 SKILL.md 决策树重新安装