Wie baue ich Modulhierarchie mit Pyo3 auf?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie baue ich Modulhierarchie mit Pyo3 auf?

by Anonymous » 19 Aug 2025, 02:36

Versuch, Module Hierarchie mit Pyo3 und diesem Code zu erstellen. < /p>

Code: Select all

pub mod types;
pub mod sources;

use pyo3::prelude::*;
use pyo3::wrap_pymodule;

use sources::file::{find_days, read_many, read_one};

#[pymodule]
fn file(_py: Python, m: &PyModule) -> PyResult {

#[pyfn(m, "find_days")]
fn find_days_py(_py: Python, dir: String) -> PyResult {
let out = find_days(&dir)?;
Ok(out.iter().map(|x| String::from(x.to_str().unwrap())).collect())
}

Ok(())
}

#[pymodule]
fn sources(_py: Python, m: &PyModule) -> PyResult {
m.add_wrapped(wrap_pymodule!(file))?;
Ok(())
}

#[pymodule]
fn cstuff(_py: Python, m: &PyModule) -> PyResult {
m.add_wrapped(wrap_pymodule!(sources))?;
// m.add("__path__", vec![""])?;
Ok(())
}
< /code>

Code erstellt und funktioniert gut, außer dass ich diesen Fehler erhalte, wenn ich versuche, ihn zu importierenIn [1]: import cstuff.sources.file
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
 in 
----> 1 import cstuff.sources.file

ModuleNotFoundError: No module named 'cstuff.sources'; 'cstuff' is not a package

Aus dem, was ich aus der Python -Dokumentation verstehe, ist das Modul ein Paket, wenn es __path __ Attribut hat. .SO Datei, die erwartet wird. Wie kann ich das beheben, gibt es eine Möglichkeit, Python zu zwingen, __Path __ ?

Top