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 to):
python foo/bar.py
How can I create a run confirguration in pycharm that runs my code using the first invokation above?
Choose Run | Run from the main menu or press Alt+Shift+F10 , and then select the desired run/debug configuration. This way, you can run any available run/debug configuration.
Alternatively, press Alt+Shift+F10 , then 0 . In the left-hand pane of the run/debug configuration dialog, click Edit configuration templates…. In the Run/Debug Configuration Templates dialog that opens, select a configuration type. Specify the desired default parameters and click OK to save the template.
You can run your tests (test cases, test suites, and so on) using run/debug configurations, in the way similar to running ordinary applications. PyCharm provides a framework for creating special run/debug configurations for testing purposes, where a test can be specified as a target.
By default, it is disabled, and PyCharm stores run configuration settings in . idea/workspace. xml.
In 2018.1 it is finally possible to specify the module name instead of the script path in the UI. There is a dropdown for changing it, to the left of the input field.
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)
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