I've written a Python module in Rust using pyo3.
Now I want to debug the module at Rust level, but I don't know how an example should look like.
I've created the following example:
use pyo3::prelude::*;
fn main() -> Result<(), ()> {
Python::with_gil(|py| {
main_(py).map_err(|e| {
// We can't display Python exceptions via std::fmt::Display,
// so print the error here manually.
e.print_and_set_sys_last_vars(py);
})
})
}
fn main_(py: Python) -> PyResult<()> {
let a2l_rs = py.import("a2l_rs")?;
let a2lFile = a2l_rs.Instance("example.a2l");
let result = a2lFile.load();
Ok(())
}
It fails to compile with the following error message:
error[E0599]: no method named `Instance` found for reference `&pyo3::prelude::PyModule` in the current scope
--> examples/test_reader.rs:15:26
|
15 | let a2lFile = a2l_rs.Instance("example.a2l");
| ^^^^^^^^ method not found in `&pyo3::prelude::PyModule`
How can I make the methods in my module visible to the example?
Thank you very much for the replies. The example now compiles, but linking fails with lot's of undefined references to Python functions.
/home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.13.2/src/types/tuple.rs:167: undefined reference to `PyTuple_New'
/usr/bin/ld: /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.13.2/src/types/tuple.rs:168: undefined reference to `PyTuple_SetItem'
/usr/bin/ld: /home/martin/Rust/a2l-rs/target/debug/examples/test_reader-4035dd3d13a547ee.4wnx3ycyz7eo6cxv.rcgu.o: in function `pyo3::ffi::object::Py_DECREF':
/home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.13.2/src/ffi/object.rs:825: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /home/martin/Rust/a2l-rs/target/debug/examples/test_reader-4035dd3d13a547ee.57e89mka91xcnn3t.rcgu.o: in function `pyo3::types::any::PyAny::call':
/home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.13.2/src/types/any.rs:207: undefined reference to `PyObject_Call'
...
My Cargo.toml in examples directory:
[package]
name = "examples"
version = "0.1.0"
authors = []
edition = "2018"
[[example]]
name = "test_reader"
path = "test_reader.rs"
[dependencies.pyo3]
version = "0.13.2"
features = ["auto-initialize"]