简体   繁体   中英

pyo3 rust module kills Python on import

I'm writing my first Rust-based Python module, and it kills the Python process on import. I've got it down to a pretty minimal example, based loosely on the html-py-ever example (which does run for me without crashing).

I'm running Python 3.8 on an M1 macbook, Python is compiled for arm64.

% python -c "import platform;print(platform.machine())"
arm64

My output, reproducer command using the files pasted below. The install should take care of any python requirements:

(rust) jeremytemp@Jeremy-McGibbons-MacBook-Pro minimal % pip install -e . && python test.py
Obtaining file:///Users/jeremytemp/rust/minimal
Installing collected packages: minimal
  Attempting uninstall: minimal
    Found existing installation: minimal 0.1.0
    Uninstalling minimal-0.1.0:
      Successfully uninstalled minimal-0.1.0
  Running setup.py develop for minimal
Successfully installed minimal-0.1.0
zsh: killed     python test.py

src/lib.rs:

use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn foo() -> PyResult<u64>{
    let u: u64 = 1;
    Ok(u)
}

#[pymodule]
fn minimal(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(foo, m)?)?;
    Ok(())
}

Cargo.toml:

[package]
name = "minimal"
version = "0.1.0"
edition = "2021"

[dependencies]
pyo3 = { features = ["extension-module"] }

[lib]
name = "minimal"
crate-type = ["cdylib"]

setup.py:

from setuptools import setup
from setuptools_rust import RustExtension

setup(
    rust_extensions=[RustExtension("minimal.minimal")],
)

setup.cfg:

[metadata]
name = minimal
version = 0.1.0
license = MIT

[options]
packages = minimal
zip_safe = False
setup_requires = setuptools-rust >= 0.12.1;
python_requires = >=3.8
include_package_data = True

minimal/__init__.py :

from .minimal import *

test.py:

import minimal

pip freeze output is

(rust) jeremytemp@Jeremy-McGibbons-MacBook-Pro minimal % pip freeze
attrs==21.4.0
beautifulsoup4==4.11.1
certifi==2021.10.8
iniconfig==1.1.1
# Editable Git install with no remote (minimal==0.1.0)
-e /Users/jeremytemp/rust/minimal
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.0.8
pytest==7.1.2
semantic-version==2.9.0
setuptools-rust==1.3.0
soupsieve==2.3.2.post1
tomli==2.0.1
typing_extensions==4.2.0

What am I doing wrong? Are there any steps I can take to get more helpful debugging output than "killed"?

Not a very satisfying answer, but the example executes fine on my windows machine. I'm assuming this is an issue with pyo3 on M1 Macs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM