How to run Flask CLI from within PyCharm under Windows How to run Flask CLI from within PyCharm under Windows flask flask

How to run Flask CLI from within PyCharm under Windows


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.

enter image description here

To use PyCharms's debugger create a file in the root say flask_debug.py:

from flask.cli import mainif __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.

enter image description here

Below shows Flask 0.12.2 quickstart app running under the PyCharm debugger and showing the defined environmental variable FLASK_APP.

enter image description here


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.

enter image description here


I'm attaching the screenshot of the working fileset and the Run/Debug Configuration for reference. This answer is thanks to the support provided by pjcunningham.

enter image description here