ModuleNotFoundError: No module named 'supermodule.submodule'; 'supermodule' is not a package
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducing example in src/lib.rs and its Cargo.toml, then run maturin develop followed by the reported Python import command. Compare the module layout produced by this setup with the expected import path; done means from supermodule.submodule import subfunction succeeds without the ModuleNotFoundError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100