-
Notifications
You must be signed in to change notification settings - Fork 880
Open
Labels
Description
🐛 Bug Reports
I am working for writing Python extension, but facing import submodule error.
ModuleNotFoundError: No module named 'supermodule.submodule'; 'supermodule' is not a package
What do I expected
Import submodule like usual Python package.
🌍 Environment
- Your operating system and version:
ArchWSL version 19.11.16.0 on Windows Subsystem Linux 2 version Windows Insiders Slow ring 10.0.19041
$ uname -a
Linux xxxxxx 4.19.84-microsoft-standard #1 SMP Wed Nov 13 11:44:37 UTC 2019 x86_64 GNU/Linux
- Your python version:
$ python -V
Python 3.8.1
- How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?:
$ pyenv virtualenv system xxxxxx
- Your rust version (
rustc --version
):
rustc 1.43.0-nightly (c9290dcee 2020-02-04)
- Are you using the latest pyo3 version? Have you tried using latest master (replace
version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
Yes.
💥 Reproducing
Please provide a minimal working example. This means both the rust code and the python.
Please also write what exact flags are required to reproduce your results.
src/lib.rs
use pyo3::prelude::*;
use pyo3::{wrap_pyfunction, wrap_pymodule};
use pyo3::types::IntoPyDict;
#[pyfunction]
fn subfunction() -> String {
"Subfunction".to_string()
}
#[pymodule]
fn submodule(_py: Python, module: &PyModule) -> PyResult<()> {
module.add_wrapped(wrap_pyfunction!(subfunction))?;
Ok(())
}
#[pymodule]
fn supermodule(_py: Python, module: &PyModule) -> PyResult<()> {
module.add_wrapped(wrap_pymodule!(submodule))?;
Ok(())
}
Cargo.toml
[package]
name = "supermodule"
version = "0.1.0"
authors = ["Tang Ziya <tcztzy@gmail.com>"]
edition = "2018"
[package.metadata.maturin]
classifier = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python",
"Programming Language :: Rust",
]
[lib]
name = "supermodule"
crate-type = ["cdylib", "rlib"]
[features]
default = []
[dependencies]
pyo3 = { git = "https://github.com/PyO3/pyo3", features = ["extension-module"] }
[dev-dependencies]
$ maturin develop
$ python -c "from supermodule.submodule import subfunction"
ModuleNotFoundError: No module named 'supermodule.submodule'; 'supermodule' is not a package
waymost, kernc, jonhue, shuternay, codeandfire and 10 more