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

后端 未结 5 1200
长情又很酷
长情又很酷 2020-12-07 20:38

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

python -m foo.bar

The following does not work (and is not supposed

5条回答
  •  清歌不尽
    2020-12-07 21:17

    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 bar.py 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

提交回复
热议问题