You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决pre-commit运行时python-Levenshtein-wheels构建失败问题

解决python-Levenshtein-wheels在Python 3.12下构建失败的问题

问题根源

Python 3.12移除了PyUnicode_GET_SIZE这类旧C API,而低版本的python-Levenshtein依赖这些废弃接口。Lucas-C/pre-commit-hooks的部分钩子会间接调用该库,未适配3.12的版本就会触发编译错误。

解决步骤

1. 强制指定兼容Python 3.12的依赖版本

在项目的pyproject.toml中添加或更新依赖声明,锁定支持3.12的python-Levenshtein版本:

[tool.poetry.dependencies]
python-Levenshtein = ">=0.21.0"

执行命令更新依赖:

poetry update python-Levenshtein

2. 覆盖pre-commit钩子的依赖配置

修改.pre-commit-config.yaml,给Lucas-C/pre-commit-hooks的相关钩子添加额外依赖,强制拉取兼容版本:

- repo: https://github.com/Lucas-C/pre-commit-hooks
  rev: v1.1.10  # 建议使用最新稳定版
  hooks:
    - id: check-symlinks
      additional_dependencies: ["python-Levenshtein>=0.21.0"]
    - id: check-merge-conflict
      additional_dependencies: ["python-Levenshtein>=0.21.0"]
    # 其他用到该依赖的钩子需同步添加配置

3. 清理pre-commit缓存并重建环境

执行以下命令清除旧缓存、重新安装钩子:

poetry run pre-commit clean
poetry run pre-commit install --install-hooks

之后重新运行目标命令:

poetry run pre-commit run --all-files

4. 临时降级Python版本(备选方案)

如果上述方法暂时无效,可切换到Python 3.11环境执行操作,等待依赖库完全适配3.12后再升级。


内容的提问来源于stack exchange,提问作者ENV

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 15:26:00