pyo3
pyo3 copied to clipboard
Fail to run cargo test.
Bug Description
When I ran cargo test
command, it failed with the following errors:
cargo test
Compiling target-lexicon v0.12.4
Compiling autocfg v1.1.0
Compiling once_cell v1.13.1
Compiling proc-macro2 v1.0.43
Compiling libc v0.2.132
Compiling quote v1.0.21
Compiling unicode-ident v1.0.3
Compiling syn v1.0.99
Compiling parking_lot_core v0.9.3
Compiling scopeguard v1.1.0
Compiling cfg-if v1.0.0
Compiling smallvec v1.9.0
Compiling unindent v0.1.10
Compiling indoc v1.0.7
Compiling lock_api v0.4.7
Compiling num-traits v0.2.15
Compiling pyo3-build-config v0.16.6
Compiling parking_lot v0.12.1
Compiling ordered-float v3.0.0
Compiling pyo3-ffi v0.16.6
Compiling pyo3 v0.16.6
Compiling pyo3-macros-backend v0.16.6
Compiling pyo3-macros v0.16.6
Compiling itemcf v1.0.0 (/Users/Myname/Desktop/Myname/Work/Github/itemcf/itemcf)
Finished test [unoptimized + debuginfo] target(s) in 34.05s
Running unittests src/lib.rs (target/debug/deps/itemcf-dc85442e1cd8d29b)
dyld: Library not loaded: @rpath/libpython3.8.dylib
Referenced from: /Users/Myname/Desktop/Myname/Work/Github/itemcf/itemcf/target/debug/deps/itemcf-dc85442e1cd8d29b
Reason: image not found
error: test failed, to rerun pass '--lib'
Caused by:
process didn't exit successfully: `/Users/Myname/Desktop/Myname/Work/Github/itemcf/itemcf/target/debug/deps/itemcf-dc85442e1cd8d29b` (signal: 6, SIGABRT: process abort signal)
### Steps to Reproduce
1. git clone [email protected]:tushushu/itemcf.git
2. check out wip-heap branch
3. cd yourdir/itemcf
4. cargo test
### Backtrace
_No response_
### Your operating system and version
MacOS big sur 11.6.8
### Your Python version (`python --version`)
Python 3.8
### Your Rust version (`rustc --version`)
1.61.0
### Your PyO3 version
0.16.4
### How did you install python? Did you use a virtualenv?
conda create -n py38 python=3.8
### Additional Info
_No response_
You need to set the -rpath
linker argument in your cargo configuration, something along the lines of what's seen here: https://pyo3.github.io/pyo3/v0.17.0/building_and_distribution.html#macos
I wonder if it would be possible for PyO3 to do it automatically. Generally this is user configuration that needs to be set appropriately for whatever redistribution of build production is going on. I think it would be reasonable to assume tests aren't redistributed so if there were something that could be deduced that would "just work" only for tests that would probably be ok.
Thanks so much for the explanations @davidhewitt I tried everything suggested in:
- https://pyo3.github.io/pyo3/v0.17.0/building_and_distribution.html#macos
It does not work. I found the solution is putting default = ["extension-module"]
in cargo.toml
file.
In this doc, it tells us to make the extension-module feature optional and default. Run tests with cargo test --no-default-features
.
The first step is useful to my case, but I need to run cargo test
instead. Otherwise, it still raises dyld: Library not loaded
error.