0

I'm trying to import my class ODSFileExtractorfrom 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?

4
  • Try using ` from .odsrw import ODSFileExtractor` with '.' operator before module name. Commented Nov 8, 2023 at 23:21
  • Does this answer your question? Python can't find module in the same folder Commented Nov 8, 2023 at 23:23
  • did you try to use from .ods_extractor import ODSFileExtractor or from . import ODSFileExtractor instead of from odsrw import ODSFileExtractor . To use import odsrw you would have to add path src to environment variable PYTHONPATH or to sys.path (in code before import) Commented Nov 9, 2023 at 13:23
  • @furas The sys.path.append('./src') did it, all other options you suggested unfortunately aren't recognized by Python. I don't know why that's the only way, but if it's like that I think my project structure altogether may be flawed. Commented Nov 9, 2023 at 16:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.