Pyo3: Can't compile to a 32-bit target with 64-bit python

Created on 17 Aug 2020  路  10Comments  路  Source: PyO3/pyo3

馃悰 Bug Reports

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.

馃實 Environment

  • Your operating system and version: 4.4.0-18362-Microsoft #836-Microsoft Mon May 05 16:04:00 PST 2020 x86_64 GNU/Linux (WSL Debian)
  • Your python version: 3.8 (64-bit)
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: apt
  • Your Rust version (rustc --version): 1.44.1
  • Your PyO3 version: 0.11.1
  • Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: No

馃挜 Reproducing

Taking 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

question

Most helpful comment

yep works nicely now, thank you!

All 10 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

konstin picture konstin  路  5Comments

fcangialosi picture fcangialosi  路  6Comments

acminor picture acminor  路  3Comments

davidhewitt picture davidhewitt  路  5Comments

sebpuetz picture sebpuetz  路  5Comments