1

I have created a number of .py files containing functions. The files would be organized in a Project_Repertory as follows:

Project_Repertory

  • Load_Repertory
    • load_functions.py
    • main.py
  • Automate_Repertory
    • main.py

In the Automate_Repertory I have a main.py file, which is to eventually be run using Apache Airflow (to which I am fully new), and I want to call the main() function of each of the other main.py files in the other folders.

However, if I write from Load_Repertory.main import main, it fails with a ModuleNotFound error. I tried working from the "Project_Repertory" instead, and then when I do from Load_Repertory.main import main it fails with the same error but pointing to a line in the code saying from load_functions import function1.

My Load_Repertory.main.py file looks like this:

import re
from load_functions import function1

def main()
    print("This is main")
    function1()

if __name__ == "__main__":
    main()

I also tried importlib and runpy unsuccessfully. How do I import the main() from the Load_Repertory.main.py file and get it to run successfully if the terminal is open on the Automate_Repertory?

Details: Python 3.13.3 on Windows 11.

0

1 Answer 1

0

Just Add __init__.py in Load_Repertory directory like this below.

enter image description here

then you can import like this

from Load_Repertory.main import main
Sign up to request clarification or add additional context in comments.

3 Comments

The screenshot shows "migrations", not "Load_Repertory'.
What is inside the __init__.py file?
@YamiOmar88 empty! It just tells the program to treat it as a Module.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.