自从切换到 Python 3.15 以来,我偶尔会遇到令人困惑的 Python 依赖错误,而我不得不记住的规则是:
如有疑问,删除 uv.lock 文件
我的大多数项目都是库,不包含 uv.lock 文件,因为库依赖为使用它的其他任何东西锁定版本是不礼貌的。
运行 uv run pytest 等往往会留下 uv.lock 文件,这些文件列在 .gitignore 中,因此不会提交到我的仓库。
但是……有时那个 uv.lock 会固定一个尚未有 Python 3.15 wheel 的依赖版本。今天早些时候的一个例子:
error: Failed to build `watchfiles==1.1.1`
cause: Call to `maturin.build_wheel` failed
error: the configured Python interpreter version (3.15) is newer
than PyO3's maximum supported version (3.14)
删除该文件并再次运行 uv run pytest 通常可以解决问题。