I'm trying to import my class ODSFileExtractor
from my file ods_extractor.py
into my main.py
.
For that reason I have an __init__.py
in my odsrw
folder where I import the class.
However, I seem unable to use my module inside my main.py
, as I get an ModuleNotFoundError: No module named 'odsrw'
when I try to run the file.
My __init__.py
inside odsrw
:
from .ods_extractor import ODSFileExtractor
__all__ = ['ODSFileExtractor',]
My main.py
:
from odsrw import ODSFileExtractor
def main():
file_extractor = ODSFileExtractor()
file_extractor.extract()
if __name__ == '__main__':
main()
My file structure:
src
└───odsrw
│ main.py
│ ods_extractor.py
│ ods_reader.py
│ __init__.py
│
└───sqlite_data
db_functions.py
db_setup.py
models.py
__init__.py
What am I doing wrong?
from .ods_extractor import ODSFileExtractor
orfrom . import ODSFileExtractor
instead offrom odsrw import ODSFileExtractor
. To useimport odsrw
you would have to add pathsrc
to environment variablePYTHONPATH
or tosys.path
(in code beforeimport
)