pyo3 rust 模块在导入时杀死 Python

pyo3 rust module kills Python on import

我正在编写我的第一个基于 Rust 的 Python 模块,它会在导入时终止 Python 进程。我已经把它归结为一个非常小的例子,大致基于 html-py-ever example(它对我来说 运行 而不会崩溃)。

我在 M1 macbook 上 运行ning Python 3.8,Python 是为 arm64 编译的。

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

我的输出,复制器命令使用下面粘贴的文件。安装应满足任何 python 要求:

(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 输出为

(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

我做错了什么?我可以采取任何步骤来获得比“杀死”更有用的调试输出吗?

不是一个非常令人满意的答案,但该示例在我的 windows 机器上执行得很好。我假设这是 M1 Mac 上的 pyo3 的问题。