Error: "Your Rust target architecture (32-bit) does not match your python interpreter (64-bit)"
I'm writing a program to run on a Raspberry Pi by cross compiling from WSL Debian. This setup has worked nicely with past projects. The rust-cpython crate does compile and work but pyo3 seems like a much nicer crate to work with.
I have tried installing 32-bit python but to no avail and compiling on the Pi itself isn't doable due to how I have it setup.
rustc --version): 1.44.1version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: NoTaking the example code from the docs, install a 64-bit python interpreter, set the --target to a 32-bit target and build.
e.g. cargo build --target=armv7-unknown-linux-gnueabihf
Thanks for your question.
If you're able to mount the Pi's filesystem you can just point PyO3 in cross-compile mode at the location of the python install on your Pi's disk. See https://pyo3.rs/v0.11.1/building_and_distribution.html#cross-compiling - you'll need to set PYO3_CROSS_LIB_DIR and PYO3_CROSS_INCLUDE_DIR to point at the right directories on your Pi.
Closing for now, but please report back here if that doesn't work.
Ah, I should've read the docs more closely.
However having now tried, I can't find a way to mount the Pi's filesystem. And as a desperate attempt I've also tried copying across the python files from the Pi's /usr/lib and /usr/include and pointing pyo3 at them. Unfortunately I get the very unhelpful error:
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
Hmm, definitely sounds like an environment issue, but perhaps we can make the experience nicer. Can you try with the branch in #1095 and see if it gives you a better error message?
Everything works!
My only difficulty was that I had to set PYO3_LIB_DIR to exactly the directory _sysconfigdata*.py was in not just lib/.
Thank you and keep up the awesome work :)
@fenjalien For reference could you give me the full path of the _sysconfigdata*.py file as well as the path to the libpython3.Y.so file on you raspberry pi please?
Sure:
_sysconfigdata*.py = /usr/lib/python3.7/_sysconfigdata_m_linux_arm-linux-gnueabihf
libpython3.Y.so = /usr/lib/python3.7/config-3.7-arm-linux-gnueabihf/libpython3.7.so
is there a symbolic link of libpython3.7.so located directly at /usr/lib/?
@fenjalien thanks for those paths, If you could try with the latest commit in #1095 and setting PYO3_CROSS_LIB_DIR to your rapsberry pi's /usr/lib directory without specifying the python directory does it work now?
yep works nicely now, thank you!
Glad to hear it! Thanks for trying it out
Most helpful comment
yep works nicely now, thank you!