Alex Flint Alex Flint - 7 months ago 33
Python Question

Create a PyCharm configuration that runs a module a la "python -m foo"

My python entrypoint needs to be run as a module (not a script), as in:

python -m

The following does not work (and is not supposed to):

python foo/

How can I create a run confirguration in pycharm that runs my code using the first invokation above?


According to man python, the -m option

-m module-name
Searches sys.path for the named module and runs the corresponding .py file as a script.

So most of the time you can just right-click on in the Project tool window and select Run bar.

If you really need to use the -m option, then specify it as an Interpreter option, with the module name as the Script in the Edit Configurations dialog:

enter image description here