PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Apache License 2.0
12.16k stars 751 forks source link

Compilation error on MacOS #3996

Closed Antonio95 closed 6 months ago

Antonio95 commented 6 months ago

Bug Description

I have a small Rust project that relies on pyo3 to run some python code of my own with methods such as Python::with_gil. The project compiles and runs on Ubuntu, but executing cargo test on a Mac results in a long error message. I have gone through the solutions proposed in other threads, for instance running the command with the recommended compilation flags and adding the following to .cargo/config (from the project root):

[target.aarch64-apple-darwin]
rustflags = [
  "-C", "link-arg=-undefined",
  "-C", "link-arg=dynamic_lookup",
]

The Mac has OS version 14.4 and an M2 chip.

I only have Python3 installed. which python3 outputs /usr/bin/python3. No python command is available.

P.S.: Thanks a lot for this very useful crate and the support you have provided other people with similar compilation issues.

Steps to Reproduce

  1. In a Mac system with the indicated characteristics, create a project whose tests use pyo3 functionality
  2. Run cargo test

Backtrace

error: linking with `cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/TeX/texbin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/antonio/.cargo/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/1v/cqcqrbfj72l886q86rzfrmyc0000gn/T/rustcYcD18Q/symbols.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.11d3taorzjsakqzt.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.16ltam1uqjxj0ytf.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.18e68nqf7tp5ba1q.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1akm9g5624bmpllk.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1bo8qwxfq3idwu8r.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1c0lz4up0rfrwc78.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1d22jai8zbx30mpc.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1dqkug1gdda0omo6.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1duj5t0mvzebmzsu.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1k3fvs2o058ft8u.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1mos84mvoq4tj8xp.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1orz6amfptozhyb2.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1r8v4wjhqi6wqb7j.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1ribnykxtqzzywk4.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1x3d2027k9tpji9u.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.1xmq5gqhwnribx9e.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.211bx6pcoojfgvbc.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.28cnz3dlre3psnqw.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.28ncjcaqflwg8l9y.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2beai3jtftjh0w2p.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2cixua3666xmcdvk.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2dicgf69l4ek5pu9.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2eqpry412cuf2yu8.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2htp4sii5uohus4e.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2jh5kic5w49zsgr.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2kob4lrdlhwzsu0v.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2l2i4r7e0gkwa9fc.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2lzrcbo53sedzhnu.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2nagarwsajtadrzu.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2ojdmnc6qxch9sh2.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2ojpfvaxtjmtgslk.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2qvithmautreqqkw.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2usx3p0bzsd8dxw.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2vkhkwp2qssg32uw.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.2xecfe00emxw7ou1.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.30td2aakxrrx78uo.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.315beftabu7f77pp.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.34vdp0eovzdhsvd2.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.37zrcjw9dj9angvx.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.38wa2ez5wjk3puls.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.39y9knxixw9q9kly.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3b43x8mnaxnt0i8o.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3elandyoye4x93m5.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3hpcjnisd21pbaos.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3hyeq05q6az6sj9c.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3i0aygf1x7wptd4e.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3ii8gsbml1gejo7q.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3k5971g1l5soaq68.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3m37thchyavftgna.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3o0jvao2ucr4oppr.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3pzq1lphjh51xb0f.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3s19i32nxits0bnx.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3sv6cgp5ickshmui.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3w3q3wvyp7r6io3k.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3x5a6bkp4inw8vv0.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3x9jyj8n19fgnz0m.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.3z34bfon66rx1dbq.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.444was9d5rpmtnf7.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.44dk2zh6xy7dfmpz.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4c2xzsmkxybchih0.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4c653blkcrbase34.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4folrmnkmp3n6bxv.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4jfyfh6wks5okvrk.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4l3uyg3yf4czw64m.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4ljuddzq1hka27yb.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4lv76aeof9yz28lm.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4qqi8hrmtljyt7o1.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4siyv0agkpw4i00i.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4som4y4nimxwfdt3.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4t8b466bvp50pxqn.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4uaeqvl0ft7ayi5b.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4uifjtcgmlyyr1k4.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4vss3m0uj5sp2gpy.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4x90h2fjbjiv1qq4.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4xcrb7jdqwcml4q2.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4zmz20urk6dwxfy4.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4zzgqzw620whn9dc.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.5238bfuboa50zear.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.52unr0asfy47wdso.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.54yl9eimstijds91.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.56ikl3sxnlvgi9d6.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.579biynukm2t05hq.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.59bwb5v6qv2usgg8.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.5en5mx70sj3mlp0i.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.5fopxbfhsfzfjv2m.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.8qltylqmmgxqt7.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.agcmiolnn18siyq.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.cef6s0p7z79l3p3.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.h1zhcpk9q5rbxj.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.k68lzo842l7ozql.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.kfibogzhx69fdt0.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.me32547702u3pp9.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.mujqtiqzbgyxxj4.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.ob1d70ia9opcl3v.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.ok00k3hpfpwr48d.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.qx08v5psedj77el.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.rzyzgs78bpret4z.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.shlodyc3vnj46t.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.uvtm3rrlavn22lc.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.wzixljk0il69g5s.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.z7ck0kosctfprrk.rcgu.o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f.4d6pun8ws03uedgp.rcgu.o" "-L" "/Users/antonio/project/project/target/debug/deps" "-L" "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib" "-L" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libtest-c39cc377f854fc15.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgetopts-01382cf70d22d84a.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunicode_width-22bca767c4aed66f.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_std-7dfc4cb9a93deba0.rlib" "/Users/antonio/project/project/target/debug/deps/libpyo3-3b08639c1f572248.rlib" "/Users/antonio/project/project/target/debug/deps/libmemoffset-bbc473185e842a8d.rlib" "/Users/antonio/project/project/target/debug/deps/libportable_atomic-f0ab600e14c578d3.rlib" "/Users/antonio/project/project/target/debug/deps/libparking_lot-9ea4cc2d0d0b2b8c.rlib" "/Users/antonio/project/project/target/debug/deps/libparking_lot_core-7d8a27646a4efeb1.rlib" "/Users/antonio/project/project/target/debug/deps/libsmallvec-037c0fc9985733cd.rlib" "/Users/antonio/project/project/target/debug/deps/liblock_api-f8eccfc5f8dc0b71.rlib" "/Users/antonio/project/project/target/debug/deps/libscopeguard-c3d0287eb98bb199.rlib" "/Users/antonio/project/project/target/debug/deps/libpyo3_ffi-b69784c648b853ca.rlib" "/Users/antonio/project/project/target/debug/deps/libunindent-86aa26ac98eaa2f9.rlib" "/Users/antonio/project/project/target/debug/deps/libmore_asserts-0b155af34379ea9b.rlib" "/Users/antonio/project/project/target/debug/deps/libcriterion-b8412540588cf487.rlib" "/Users/antonio/project/project/target/debug/deps/libciborium-48db91e3b8459935.rlib" "/Users/antonio/project/project/target/debug/deps/libciborium_ll-93ad9c109cb84e07.rlib" "/Users/antonio/project/project/target/debug/deps/libhalf-52148bdbf195088e.rlib" "/Users/antonio/project/project/target/debug/deps/libciborium_io-f5b593c1b1cbe409.rlib" "/Users/antonio/project/project/target/debug/deps/libclap-c99257ad8da7d934.rlib" "/Users/antonio/project/project/target/debug/deps/libclap_builder-a786d56ffffe00fc.rlib" "/Users/antonio/project/project/target/debug/deps/libclap_lex-03cd953e4eaef625.rlib" "/Users/antonio/project/project/target/debug/deps/libanstyle-61b820cf849df55a.rlib" "/Users/antonio/project/project/target/debug/deps/liboorandom-ba95dd511b0979cc.rlib" "/Users/antonio/project/project/target/debug/deps/libanes-96f10cfa643a6b2c.rlib" "/Users/antonio/project/project/target/debug/deps/libtinytemplate-820db756a2373161.rlib" "/Users/antonio/project/project/target/debug/deps/libcriterion_plot-719594ea997e1d83.rlib" "/Users/antonio/project/project/target/debug/deps/libitertools-017557b9e0f99e82.rlib" "/Users/antonio/project/project/target/debug/deps/libcast-fecfeaf6d185507e.rlib" "/Users/antonio/project/project/target/debug/deps/libwalkdir-8f3646a6ca982c10.rlib" "/Users/antonio/project/project/target/debug/deps/libsame_file-6537afcada5eab1b.rlib" "/Users/antonio/project/project/target/debug/deps/libserde_json-284627b550b7ca13.rlib" "/Users/antonio/project/project/target/debug/deps/libitoa-eccec66de25c4b61.rlib" "/Users/antonio/project/project/target/debug/deps/libryu-dd40085d417ba2fa.rlib" "/Users/antonio/project/project/target/debug/deps/libserde-484e58dbd5bcbf45.rlib" "/Users/antonio/project/project/target/debug/deps/libregex-ab6baff9885864cf.rlib" "/Users/antonio/project/project/target/debug/deps/libregex_automata-d2d04ebd161fbaf1.rlib" "/Users/antonio/project/project/target/debug/deps/libregex_syntax-78ee0f3d47578414.rlib" "/Users/antonio/project/project/target/debug/deps/libis_terminal-112f24bc5bb0c779.rlib" "/Users/antonio/project/project/target/debug/deps/liblibc-ad35a408eba32547.rlib" "/Users/antonio/project/project/target/debug/deps/libsha2-193e60eec58e9370.rlib" "/Users/antonio/project/project/target/debug/deps/libhashbrown-d2411dd343bdcbea.rlib" "/Users/antonio/project/project/target/debug/deps/libahash-6ecf4a03b632878f.rlib" "/Users/antonio/project/project/target/debug/deps/libonce_cell-e9b1da7b0201a63a.rlib" "/Users/antonio/project/project/target/debug/deps/libcfg_if-794b620668093871.rlib" "/Users/antonio/project/project/target/debug/deps/libzerocopy-9a39199dd671288f.rlib" "/Users/antonio/project/project/target/debug/deps/liballocator_api2-5e1f0f7405f5bd1a.rlib" "/Users/antonio/project/project/target/debug/deps/libitertools-6c416051e9b92948.rlib" "/Users/antonio/project/project/target/debug/deps/librayon-7128aa61da8d48b0.rlib" "/Users/antonio/project/project/target/debug/deps/librayon_core-270daed6c8cea8b3.rlib" "/Users/antonio/project/project/target/debug/deps/libcrossbeam_deque-ea43b246706f0983.rlib" "/Users/antonio/project/project/target/debug/deps/libcrossbeam_epoch-bafc158c04b52641.rlib" "/Users/antonio/project/project/target/debug/deps/libcrossbeam_utils-eb81983f5893527a.rlib" "/Users/antonio/project/project/target/debug/deps/libeither-0298107a4cc6cb83.rlib" "/Users/antonio/project/project/target/debug/deps/libarrayvec-78433b30252dff87.rlib" "/Users/antonio/project/project/target/debug/deps/libzeroize-8ecbd1bf6ada23f7.rlib" "/Users/antonio/project/project/target/debug/deps/libdigest-bb1a5222323df030.rlib" "/Users/antonio/project/project/target/debug/deps/libsubtle-8cd8c819f1c3823f.rlib" "/Users/antonio/project/project/target/debug/deps/libblock_buffer-99e99ff48db4e8ef.rlib" "/Users/antonio/project/project/target/debug/deps/libcrypto_common-7e087b87e58f3b22.rlib" "/Users/antonio/project/project/target/debug/deps/libgeneric_array-86c291c221078db1.rlib" "/Users/antonio/project/project/target/debug/deps/libtypenum-58e2dac5dfc69d7f.rlib" "/Users/antonio/project/project/target/debug/deps/libnum_bigint-7364ba1c189de03d.rlib" "/Users/antonio/project/project/target/debug/deps/libnum_integer-efe7842929b1f75e.rlib" "/Users/antonio/project/project/target/debug/deps/libnum_traits-9b03ef55deb66c76.rlib" "/Users/antonio/project/project/target/debug/deps/librand-7ab6c97901fe5e8f.rlib" "/Users/antonio/project/project/target/debug/deps/librand_chacha-37185d1f3f6f8831.rlib" "/Users/antonio/project/project/target/debug/deps/libppv_lite86-515d68f786e3c21e.rlib" "/Users/antonio/project/project/target/debug/deps/librand_core-49c5275fa8ae49b9.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-2723cfcfa18bc839.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-7089f2245ea449c6.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-8873111c3f7fc4ad.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-342843605ad432d2.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-d63c8eefe44ebaab.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-cf4230cd59e523ef.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-f678c3d2dcecf4f0.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-fb071490c7de5608.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-63dd4f2049585585.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-dace08caef99bec1.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-20b8f4ccc2ed0bab.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-9f85188b1351fc20.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-ae31200223f9d591.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-0a3bc91130e4263a.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-0d8c8195b83ea7f7.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-fce2a9bd028a2944.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-e5afe4e689972eee.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-113e29613e2cc3c4.rlib" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-0faa98e433ca4c9a.rlib" "-lpython3.9" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/Users/antonio/.rustup/toolchains/nightly-2024-01-31-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/antonio/project/project/target/debug/deps/common-ceffc4fba13c162f" "-Wl,-dead_strip" "-nodefaultlibs" "-undefined" "dynamic_lookup"
  = note: ld: warning: search path '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib' not found
          ld: library 'python3.9' not found
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Your operating system and version

MacOS Sonoma 14.4

Your Python version (python --version)

Python 3.9.6 (as mentioned, this is python3 --version: no python command on my system)

Your Rust version (rustc --version)

rustc 1.77.0-nightly (I have rust-toolchain set to nightly)

Your PyO3 version

0.20.3

How did you install python? Did you use a virtualenv?

As part of the command line developer tools.

More context: in the last versions of MacOS, python doesn't come installed by default, but there is a stub at usr/bin/python3. Upon trying to run it for the first time, one is prompted to install the dev tools, which results in the python3 binary at that path. More info here.

N.B.: Despite what the link says, installing the dev tools doesn't result in python2 being installed as a binary in /usr/bin/python in newer version os MacOS (like mine).

Additional Info

It seems (I might be misjudging things, as I am not very familiar with the issue) that the linker is looking for python in /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib. But I don't even have an /Applications/Xcode.app folder. I have python binaries at /usr/bin/python3 and at /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9.

davidhewitt commented 6 months ago

This looks like an environment configuration issue. It seems like you're also sensing this.

Can you try running your compile with the environment variable PYO3_PRINT_CONFIG=1? i.e. PYO3_PRINT_CONFIG=1 cargo test. That will probably give us ideas what is going on.

Antonio95 commented 6 months ago

Thank you for replying so quickly! You are absolutely right about my suspicions. I also think my python installation is probably not uncommon among users whose Mac came with a relatively recent version of MacOS, so I hope this will be of help to many people.

Here's the output of the PYO3_PRINT_CONFIG=1 cargo test


   Compiling pyo3-ffi v0.20.3
error: failed to run custom build command for `pyo3-ffi v0.20.3`

Caused by:
  process didn't exit successfully: `/Users/antonio/project/project/target/debug/build/pyo3-ffi-66d1fe44272a584f/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=PYO3_CROSS
  cargo:rerun-if-env-changed=PYO3_CROSS_LIB_DIR
  cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_VERSION
  cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_IMPLEMENTATION
  cargo:rerun-if-env-changed=PYO3_PRINT_CONFIG

  -- PYO3_PRINT_CONFIG=1 is set, printing configuration and halting compile --
  implementation=CPython
  version=3.9
  shared=true
  abi3=false
  lib_name=python3.9
  lib_dir=/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib
  executable=/Library/Developer/CommandLineTools/usr/bin/python3
  pointer_width=64
  build_flags=
  suppress_build_script_link_lines=false

  note: unset the PYO3_PRINT_CONFIG environment variable and retry to compile with the above config```
davidhewitt commented 6 months ago

Strange. /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib does exist on my machine.

Can you try installing Xcode from the macOS App Store, if you don't already have it? I assume that for whatever awful reason the macOS distribution of Python assumes that developers have Xcode installed.

Alternatively, just install Python 3.12 from python.org or homebrew and use that for more features and performance 😂

Antonio95 commented 6 months ago

I've done as you proposed and installed Xcode. Now the path you mentioned in your last message also exists on my machine. However, I still get a build error:

dyld[12307]: Library not loaded: @rpath/Python3.framework/Versions/3.9/Python3
  Referenced from: <85811BC8-D961-30BB-BC9B-38AD5AD9768A> /Users/antonio/project/project/target/debug/deps/common-a56ca8383ddf5208
  Reason: no LC_RPATH's found
error: test failed, to rerun pass `-p hcs-common --lib`

Caused by:
  process didn't exit successfully: `/Users/antonio/project/project/target/debug/deps/common-a56ca8383ddf5208` (signal: 6, SIGABRT: process abort signal)

When setting PYO3_PRINT_CONFIG=1, I get:

error: failed to run custom build command for `pyo3-ffi v0.20.3`

Caused by:
  process didn't exit successfully: `/Users/antonio/project/project/target/debug/build/pyo3-ffi-66d1fe44272a584f/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=PYO3_CROSS
  cargo:rerun-if-env-changed=PYO3_CROSS_LIB_DIR
  cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_VERSION
  cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_IMPLEMENTATION
  cargo:rerun-if-env-changed=PYO3_PRINT_CONFIG

  -- PYO3_PRINT_CONFIG=1 is set, printing configuration and halting compile --
  implementation=CPython
  version=3.9
  shared=true
  abi3=false
  lib_name=python3.9
  lib_dir=/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib
  executable=/Applications/Xcode.app/Contents/Developer/usr/bin/python3
  pointer_width=64
  build_flags=
  suppress_build_script_link_lines=false

  note: unset the PYO3_PRINT_CONFIG environment variable and retry to compile with the above config

For the record, I still have the .cargo/config file with the same contents I mentioned on the OP.

davidhewitt commented 6 months ago

See the section about rpath in the bottom of the macOS building entry: https://pyo3.rs/v0.21.0/building-and-distribution.html?highlight=rpath#macos

Antonio95 commented 6 months ago

That finally fixed execution. Thank you so much!

davidhewitt commented 6 months ago

Glad to hear!