Wing Tips: Using "python -m" in Wing Python IDE

Feb 18, 2020


Let's take a look at how Wing can be configured to debug modules that need to be launched with python -m. This command line option for Python allows searching the Python Path for the name of a module or package, and then loading and executing it. This capability was introduced way back in Python 2.4, and then extended in Python 2.5 through PEP 338 . However, it only came into widespread use relatively recently, for example to launch venv, black, or other command line tools that are shipped as Python packages.

Launching Modules

To configure Wing to launch a module by name with python -m, create a Named Entry Point from the Debug menu, select Named Module, and enter the module or package name and any run arguments:

/images/blog/python-m/named-entry-point-module.png

The above is equivalent to this command line:

python -m mymodule one two

The named entry point can be set as the main entry point for your project under the Debug/Execute tab of Project Properties, from the Project menu:

/images/blog/python-m/main-entry-point.png

Or it can be launched from the Debug > Debug Named Entry Point menu or by assigning a key binding to it in the named entry point manager dialog.

Launching Packages

Packages can also be launched in this way, if they include a file named __main__.py to define the package's main entry point:

/images/blog/python-m/named-entry-point.png

Setting Python Path

Whether launching a module or package, the name has to be found on the Python Path that you've configured for your project. If Wing fails to find the module, add its parent directory to Python Path under the Environment tab in Project Properties:

/images/blog/python-m/python-path.png

That's it for now! We'll be back soon with more Wing Tips for Wing Python IDE.

As always, please don't hesitate to email support@wingware.com if you run into problems or have any questions.



Share this article: