How to fix “Attempted relative import in non-package” even with __init__.py

To elaborate on Ignacio Vazquez-Abrams’s answer: The Python import mechanism works relative to the __name__ of the current file. When you execute a file directly, it doesn’t have its usual name, but has “__main__” as its name instead. So relative imports don’t work. You can, as Igancio suggested, execute it using the -m option. If … Read more