我正在尝试让 PyO3 在我的 Mac M1 mini 上工作。如果我按照步骤开始使用 PyO3:
$ mkdir string_sum
$ cd string_sum
$ python -m venv .env
$ source .env/bin/activate
$ pip install maturin
我得到“rustc ...未安装或不在PATH中”:
> maturin init
✔ What kind of bindings to use? · pyo3
✨ Done! Initialized project /Users/tweedle/projects/string_sum
> maturin develop
maturin failed
Caused by: rustc, the rust compiler, is not installed or not in PATH. This package requires Rust and Cargo to compile extensions. Install it through the system's package manager or via https://rustup.rs/.
我看到这个错误在 PyO3 问题中出现了很多,但通常通过安装 rustup 来解决。但是我已经安装了 rustup 并且在路径上:
❯ rustc --version
rustc 1.58.1 (db9d1b20b 2022-01-20)
> rustup which rustc
/Users/tweedle/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc
> export PATH="$PATH:~/.rustup/toolchains/stable-aarch64-apple-darwin/bin:~/.cargo/bin"
> maturin develop
maturin failed
Caused by: rustc, the rust compiler, is not installed or not in PATH. This package requires Rust and Cargo to compile extensions. Install it through the system's package manager or via https://rustup.rs/.
(再次添加到 PATH 以确保。)我也尝试了 x86 工具链,结果相同。Cargo build 在 maturin 生成的string_sum
rust 代码上也运行良好:
> cargo build
Updating crates.io index
Compiling proc-macro2 v1.0.36
Compiling unicode-xid v0.2.2
Compiling pyo3-build-config v0.15.1
Compiling syn v1.0.86
Compiling proc-macro-hack v0.5.19
Compiling once_cell v1.9.0
Compiling libc v0.2.116
Compiling cfg-if v1.0.0
Compiling parking_lot_core v0.8.5
Compiling scopeguard v1.1.0
Compiling smallvec v1.8.0
Compiling unindent v0.1.7
Compiling instant v0.1.12
Compiling lock_api v0.4.6
Compiling quote v1.0.15
Compiling parking_lot v0.11.2
Compiling pyo3 v0.15.1
Compiling paste-impl v0.1.18
Compiling paste v0.1.18
Compiling pyo3-macros-backend v0.15.1
Compiling indoc-impl v0.3.6
Compiling indoc v0.3.6
Compiling pyo3-macros v0.15.1
Compiling string_sum v0.1.0 (/Users/tweedle/projects/string_sum)
Finished dev [unoptimized + debuginfo] target(s) in 9.73s
我的 M1 设置、自制设置、rust 设置、python 设置或其他我错过的东西是不是很奇怪?
更多信息:
> neofetch
'c. tweedle@mini.local
,xNMM. ------------------
.OMMMMo OS: macOS 12.2 21D49 arm64
OMMM0, Host: Macmini9,1
.;loddo:' loolloddol;. Kernel: 21.3.0
cKMMMMMMMMMMNWMMMMMMMMMM0: Uptime: 1 day, 2 hours, 12 mins
.KMMMMMMMMMMMMMMMMMMMMMMMWd. Packages: 116 (brew)
XMMMMMMMMMMMMMMMMMMMMMMMX. Shell: bash 5.1.16
;MMMMMMMMMMMMMMMMMMMMMMMM: Resolution: 1920x1080
:MMMMMMMMMMMMMMMMMMMMMMMM: DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX. WM: Rectangle
kMMMMMMMMMMMMMMMMMMMMMMMMWd. Terminal: kitty
.XMMMMMMMMMMMMMMMMMMMMMMMMMMk CPU: Apple M1
.XMMMMMMMMMMMMMMMMMMMMMMMMK. GPU: Apple M1
kMMMMMMMMMMMMMMMMMMMMMMd Memory: 1975MiB / 16384MiB
;KMMMMMMMWXXWMMMMMMMk.
.cooc,. .,coo:.
> rustup --version
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.58.1 (db9d1b20b 2022-01-20)`
> rustc --version
rustc 1.58.1 (db9d1b20b 2022-01-20)
> python --version
Python 3.9.10
> maturin --version
maturin 0.12.6
我也尝试过使用setuptools-rust
类似的效果,既直接调用 setup.py 也使用pip install .
.