0

I have a main project folder with one .py file inside, and a subdirectory with two .py files inside. From the main file (main.py), I create an object of a subdirectory file (subFile.py). Then, the subdirectory file imports the other subdirectory file (header_footer.py), which is a subclass of FPDF. I get the error: ModuleNotFoundError: No module named 'header_footer'. I have tried throwing import statements all around, every which way I can, with periods, without periods, and I just don't understand which version is right. I even put blank init.py files in each directory because I've heard that fixes it.

Here is the file structure:

Project
└── __init__.py
└── main.py
└── Sub
    └── __init__.py
    └── subFile.py
    └── header_footer.py

And here are the three files. I made test files to closely match my code structure without the other frills.

main.py

from Sub.subFile import *

testObject = subFile()
print("Success")

subFile.py

from fpdf import FPDF
from header_footer import *

class subFile:
    def __init__(self):
        self.name = "garbage"
        pdf = header_footer()

header_footer.py

from fpdf import FPDF

class header_footer(FPDF):
    def __init_subclass__(self):
        self.name = "blank"
Kieran Paddock
  • 375
  • 1
  • 5
  • 15
  • I am afriaid this is frequently asked question - [example](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – mucka Jan 31 '20 at 14:30
  • 1
    Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – mucka Jan 31 '20 at 14:30

0 Answers0