Module import fails when creating and importing from Rust #2649
-
This is probably just a documentation issue, I can't find the answer on pyo3.rs. This code: use pyo3::prelude::*;
fn main() {
Python::with_gil(|py| -> PyResult<()> {
let mod1 = PyModule::new(py, "my_module")?;
let mod2 = PyModule::import(py, "my_module")?;
Ok(())
})
.expect("didn't import module");
} produces
what I expected to happen what I'm trying to do use pyo3::prelude::*;
fn main() {
Python::with_gil(|py| -> PyResult<()> {
let mod1 = PyModule::new(py, "my_module")?;
py.run("import my_module", None, None)?;
Ok(())
})
.expect("didn't import module");
} Suggestion |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Creating a new module does not make it known to the import machinery. You'll also have to add it to the module registry ( |
Beta Was this translation helpful? Give feedback.
Creating a new module does not make it known to the import machinery. You'll also have to add it to the module registry (
sys.modules
) sinceimport
will not find it in the usual way (looking for files onsys.path
).