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

后端 未结 5 1179
长情又很酷
长情又很酷 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:12

    There is a workaround I use for my scripts, which do use relative imports.

    python -m actually invokes a script called runpy.py which is part of a standard Python installation. These two invocations are equivalent:

    python -m my_module.a.b module_arguments
    python python_lib_directory/runpy.py my_module.a.b module_arguments
    

    Use the latter method to setup your Run/Debug Configuration:

    Script: python_lib_directory/runpy.py

    Script parameters: my_module.a.b module_arguments

    Interpreter options: (leave blank, no -m required)

提交回复
热议问题