Add missing __init__.py files to MegaDetector and megadetector directories#168
Add missing __init__.py files to MegaDetector and megadetector directories#168PetervanLunteren wants to merge 2 commits intoagentmorris:mainfrom
__init__.py files to MegaDetector and megadetector directories#168Conversation
|
The top-level "MegaDetector" folder (i.e., the root of the repo) is not a package, so this:
...is not a good idea. You should always be doing this:
This will work if you've installed the megadetector Python package (or the megadetector-utils Python package), or if the repo root is on your PYTHONPATH. Lots of other problems will come up later if you try to treat the repo root as a package; it's not testable, it includes non-Python stuff, it breaks the way megadetector modules import each other, etc. The "megadetector" folder is the root of the package. This is a pretty typical package structure, where one folder in the repo is the root from which a Python package is built, and stuff like docs live outside the package root. So, I don't think we want to add an Adding an
...which I promise you don't want to do, so I think that's the main issue to address to avoid problems later. Then let's come back here and see whether you still need an |
|
More specifically, I confirmed that adding an |
|
I checked and importing like works! No need for this PR. Thanks! |
|
In fact, it was a really stupid mistake on my side (I was adding the wrong path to sys)... All good now!! |
|
It was actually a good reminder to add the top-level init.py (in the package folder, not the repo root), so I did it anyway. It's not required for recent Python versions, but it's a best practice, and omitting it was lazy on my part. So, your mistake had a silver lining. Thanks! |
My AI friends advised me to add these
__init__.pyfiles so that I can properly import the modules in thedetectiondir. I had some really weird behaviour in my AddaxAI streamlit app. It seems to be resolved with these two extra empty files.I asked ChatGPT to write some explanation:
This PR adds two missing
__init__.pyfiles:MegaDetector/__init__.pyMegaDetector/megadetector/__init__.pyThe
MegaDetector/megadetector/detection/__init__.pyfile already exists.Adding these files ensures that Python treats these directories as proper packages, enabling imports like:
to work reliably across different environments and tools (e.g., Streamlit, pytest, PyInstaller).
Without these files, Python can fail to locate modules properly, leading to errors such as KeyError or ImportError.
This change improves import consistency and overall package stability.