I've been trying to get the Flask CLI to debug from within PyCharm with no success. I've tried the recommended procedures listed here. However, this doesn't work under Windows since flask.exe is an executable and not a script. Renaming flask.exe to flask does not work either. This causes the following exception:
Jetbrains has an active incident report in YouTrack for this, but there's been no activity done on it yet, with the Kanban State set to "Not On Board", so it looks like it's going to be sometime before the issue is addressed.
Any help would be greatly appreciated.
EDIT: Using Pycharm run works properly. Trying to run using the Pycharm debugger causes the exception
EDIT 2: Results after creating flask_debug.py file as recommended:
Firstly, rename flask.py back to flask.exe.
In PyCharm's Run Configuration dialog manually enter the full path to the Flask executable in the Script: text box. Don't use the browse button as it filters on Python scripts (.py files).
See screenshot. In this instance there is a virtual environment called "href" and the flask executable is in the Scripts sub-directory.
To use PyCharms's debugger create a file in the root say flask_debug.py:
from flask.cli import main
if __name__ == '__main__':
main(as_module=False)
Then setup PyCharm to run this script passing any Flask CLI parameters as required. See screenshot below showing Run/Debug configuration and the debugger stopped at a breakpoint.
Below shows Flask 0.12.2 quickstart app running under the PyCharm debugger and showing the defined environmental variable FLASK_APP.
In the latest version of PyCharm, there's an option to run by Module name instead of by file. Using "flask" as the module name works as well and doesn't require you to create a flask_debug.py file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With