如何无需修改Cargo.toml用Cargo更新跨大版本依赖?
用Cargo命令升级pyo3到0.21.2的方法
你的问题根源在于Cargo.toml里的版本约束:pyo3 = "0.20.0" 等价于语义化版本规则的^0.20.0,这个约束限制了只能升级到0.20.x系列的补丁版本,无法跨越到0.21.x的大版本,因此cargo update会因版本不匹配报错。
无需手动编辑Cargo.toml的话,可直接用cargo add命令修改依赖版本:
- 升级到指定的0.21.2版本:
cargo add pyo3@0.21.2
- 若想直接升级到pyo3的最新稳定版,也可以用:
cargo add pyo3@latest
执行上述命令后,Cargo会自动修改你的Cargo.toml,将pyo3的版本更新为目标版本,同时重新生成Cargo.lock并完成依赖解析。之后执行cargo build验证构建,再根据pyo3 0.21.x的变更文档修复可能出现的破坏性改动即可。
原问题相关信息
原Cargo.toml内容:
[package] name = "eight-ball" version = "0.1.0" edition = "2021" [lib] name = "eight_ball" crate-type = ["cdylib"] [dependencies] itertools = "0.12.1" pyo3 = "0.20.0"
报错信息:
error: failed to select a version for the requirement `pyo3 = "^0.20.0"` candidate versions found which didn't match: 0.21.2 location searched: crates.io index required by package `eight-ball v0.1.0 (/home/harry/Documents/eight-ball)` perhaps a crate was updated and forgotten to be re-vendored?
内容的提问来源于stack exchange,提问作者whatf0xx
相关产品推荐
相关产品推荐

