PyO3 / maturin

Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
https://maturin.rs
Apache License 2.0
3.91k stars 271 forks source link

python target is not used on M1 #979

Closed twiecki closed 2 years ago

twiecki commented 2 years ago

Bug Description

>>maturin develop
🍹 Building a mixed python/rust project
🔗 Found pyo3 bindings
🐍 Found CPython 3.10 at /Users/twiecki/miniforge3/envs/pymc4/bin/python
📡 Using build options bindings from pyproject.toml
   Compiling autocfg v1.1.0
   Compiling cfg-if v1.0.0
   Compiling once_cell v1.12.0
   Compiling libc v0.2.126
   Compiling proc-macro2 v1.0.39
   Compiling target-lexicon v0.12.4
   Compiling unicode-ident v1.0.1
   Compiling syn v1.0.96
   Compiling scopeguard v1.1.0
   Compiling crossbeam-utils v0.8.9
   Compiling libm v0.2.2
   Compiling parking_lot_core v0.9.3
   Compiling rayon-core v1.9.3
   Compiling ppv-lite86 v0.2.16
   Compiling smallvec v1.8.0
   Compiling crossbeam-queue v0.3.5
   Compiling rawpointer v0.2.1
   Compiling either v1.6.1
   Compiling unindent v0.1.9
   Compiling indoc v1.0.6
   Compiling num-traits v0.2.15
   Compiling memoffset v0.6.5
   Compiling crossbeam-epoch v0.9.9
   Compiling lock_api v0.4.7
   Compiling num-integer v0.1.45
   Compiling rayon v1.5.3
   Compiling matrixmultiply v0.3.2
   Compiling itertools v0.10.3
   Compiling getrandom v0.2.7
   Compiling num_cpus v1.13.1
   Compiling rand_core v0.6.3
   Compiling quote v1.0.18
   Compiling crossbeam-channel v0.5.5
   Compiling pyo3-build-config v0.16.5
   Compiling parking_lot v0.12.1
   Compiling rand_chacha v0.3.1
   Compiling crossbeam-deque v0.8.1
   Compiling crossbeam v0.8.1
   Compiling rand v0.8.5
   Compiling num-complex v0.4.1
   Compiling ndarray v0.15.4
   Compiling rand_distr v0.4.3
   Compiling pyo3-ffi v0.16.5
   Compiling pyo3 v0.16.5
   Compiling pyo3-macros-backend v0.16.5
   Compiling thiserror-impl v1.0.31
   Compiling multiversion-macros v0.6.1
   Compiling pyo3-macros v0.16.5
   Compiling multiversion v0.6.1
   Compiling thiserror v1.0.31
   Compiling nuts-rs v0.2.0
   Compiling numpy v0.16.2
   Compiling nutpie v0.1.0 (/Users/twiecki/projects/nutpie)
    Finished dev [unoptimized + debuginfo] target(s) in 20.92s
📦 Built wheel for CPython 3.10 to /var/folders/mn/0x4pxw0n61lf479ndp07r0gr0000gn/T/.tmpXjpvDA/nutpie-0.1.0-cp310-cp310-macosx_10_7_x86_64.whl
💥 maturin failed
  Caused by: pip install in /Users/twiecki/miniforge3/envs/pymc4 failed running ["-m", "pip", "--disable-pip-version-check", "install", "--force-reinstall", "/var/folders/mn/0x4pxw0n61lf479ndp07r0gr0000gn/T/.tmpXjpvDA/nutpie-0.1.0-cp310-cp310-macosx_10_7_x86_64.whl"]: exit status: 1
--- Stdout:

--- Stderr:
ERROR: nutpie-0.1.0-cp310-cp310-macosx_10_7_x86_64.whl is not a supported wheel on this platform.
---
>>/Users/twiecki/miniforge3/envs/pymc4/bin/python -c 'import sysconfig; print(sysconfig.get_platform())'
macosx-11.0-arm64

It seems to instead use this one:

>>which python
python is /Users/twiecki/miniforge3/envs/pymc4/bin/python
python is /usr/local/bin/python
(pymc4) --(12:20:44)--(MacBook-Air-4)--(~/projects/nutpie     )--(master)
>>/usr/local/bin/python -c 'import sysconfig; print(sysconfig.get_platform())'
macosx-10.13-x86_64

But I can't see where it's it setting from.

Your Python version (python -V)

Python 3.10.4

Your pip version (pip -V)

pip 22.1.2 from /Users/twiecki/miniforge3/envs/pymc4/lib/python3.10/site-packages/pip (python 3.10)

What bindings you're using

pyo3

Does cargo build work?

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

Steps to Reproduce

  1. Use M1
  2. Run maturin develop
messense commented 2 years ago

I think you installed x86_64 Rust by default, can you run rustc -vV and paste the output here?

twiecki commented 2 years ago
>>rustc -vV
rustc 1.59.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-apple-darwin
release: 1.59.0
LLVM version: 13.0.0
messense commented 2 years ago

host: x86_64-apple-darwin

Yup, reinstall your Rust toolchain and make sure it outputs host: aarch64-apple-darwin should resolve your issue.

messense commented 2 years ago

Although we should be able to detect the arm64 Python and use --target aarch64-apple-darwin automatically in maturin, so I'll keep this issue open for now.

twiecki commented 2 years ago

That fixed it -- thanks! I had to reinstall homebrew.