By design, Python 3 cannot run a module that contains relative imports as a script. Attempting to do so yields the following error:
$ python mypackage/run.py
[...traceback...]
SystemError: Parent module '' not loaded, cannot perform relative import
The solution is to invoke the module with python -m mypackage.run
instead of the more familiar python mypackage/run.py
.
In Flask, the latter is how one normally runs the development server. However, the Flask development server immediately spawns a child process that reloads the code (and subsequently reloads code when files are changed on disk).
The result is this:
$ python -m mypackage.run
* Running on http://127.0.0.1:5000/
* Restarting with reloader
[...traceback...]
SystemError: Parent module '' not loaded, cannot perform relative import
So now the server starts properly, but the child process reloads the code improperly.