1

I've been trying to import a sub-package from a main package from another sub-package in a quite different folder hierarchy. It's specifically from a file "predict.py" under web/flask trying to import gvtools under greenvision/ I've tried the following methods:

from ...greenvision.gvtools import *
from ...greenvision import gvtools
import gvapps.greenvision.gvtools
from gvapps.greenvision.gvtools import *
from gvapps.greenvision import gvtools

All of them give the error described in the title or "no module named gvapps". I'm not sure this package structure works. What could be the issue?

All folders contain init.py as you see.

  • 1
    https://sinoroc.gitlab.io/kb/python/python_imports.html – sinoroc Feb 16 '23 at 10:49
  • You're correct. Turns out I don't know much about packages still. Going deeper into another link I found, I was able to clarify myself more aswell: https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time In summary, it's literally that, since I ran this script with `python predict.py` it thought itself as __main__, which can't be considered inside a package, therefore I had to do `python -m gvapps.greenvision.predict` to run the file as a module and recognize itself as a package related to other packages. – Oz_Magician Feb 17 '23 at 02:08

0 Answers0