Wingware Blog

May 06, 2015

Wing IDE is an integrated development environment that can be used to develop and debug Python code running on the Raspberry Pi. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code.

Introduction

The Raspberry Pi is not really capable of running Wing IDE itself, but you can set up Wing IDE on a computer connected to the Raspberry Pi to work on and debug Python code remotely.

To do this, you will first need (1) a network connection between the Raspberry Pi and the computer where Wing IDE will be running, and (2) a way to share files between the two computers.

The easiest way to connect the Raspberry Pi to your network is with ethernet, or see the instructions at the end of Using Wing IDE with Raspberry Pi for configuring a wifi connection.

For file sharing, use Samba, or simply transfer a copy of your files to the Raspberry Pi using scp or rsync.

Installing and Configuring the Debugger

Once you have a network connection and some sort of file sharing set up, the next step is to install and configure Wing IDE's debugger. This is done as follows:

  • If you do not already have Wing IDE 5.1.5 or later installed, download a free trial on Windows, Linux, or OS X.
  • Download the Raspberry Pi debugger package to your Raspberry Pi and unpack it with tar xzf wing-debugger-raspbian-5.1.5-1.tgz. This creates a directory named wing-debugger-raspbian-5.1.5-1.
  • Launch Wing IDE and make sure that Accept Debug Connections is checked when you click on the bug icon in the lower left of Wing's main window. Hovering the mouse over the bug icon will show additional status information, including the port Wing is listening on, which should be 50005 by default.
  • Copy wingdebugpw from the machine where you have Wing IDE installed to the Raspberry Pi and place it into the directory wing-debugger-raspbian-5.1.5-1. This file is located in the Settings Directory, which is listed 5th in Wing's About box.
  • On the Raspberry Pi, use /sbin/ifconfig to determine the IP address of the Raspberry Pi (not 127.0.0.1, but instead the number listed under eth0 or wlan0 if you're using wifi).
  • On the host where Wing IDE is running (not the Raspberry Pi), establish an ssh reverse tunnel to the Raspberry Pi so the debugger can connect back to the IDE. On Linux and OS X this is done as follows:

    ssh -N -R 50005:localhost:50005 <user>@<rasp_ip>
    

    You'll need to replace <user>@<rasp_ip> with the login name on the Raspberry Pi and the ip address from the previous step.

    The -f option can be added just after ssh to cause ssh to run in the background. Without this option, you can use Ctrl-C to terminate the tunnel. With it, you'll need to use ps and kill to manage the process.

    On Windows, use PuTTY to configure an ssh tunnel using the same settings on the Connections > SSH > Tunnels page: Set Source port to 50005, Destination to localhost:50005, and select the Remote radio button, then press the Add button. Once this is done the tunnel will be established whenever PuTTY is connected to the Raspberry Pi.

  • In Wing IDE's Preferences, use the Debugger > External/Remote > Location Map preference to set up a mapping from the location of your files on the remote host (the Raspberry Pi) and the machine where the IDE is running.

    For example, if you have files in /home/pi/ on your Raspberry Pi that match those in /Users/pitest/src/ on the machine where Wing is running, then you would add those two to the location mapping for 127.0.0.1, with home/pi/ as the remote directory and /Users/pitest/src/ as the local directory.

    Don't add a location map for the Raspberry Pi's ip address because your ssh tunnel makes it look like the connection is coming from 127.0.0.1 and not the Raspberry Pi.

Invoking the Debugger

There are two ways to invoke the debugger: (1) from the command line, or (2) from within your Python code. The latter is useful if debugging code running under a web server or other environment not launched from the command line.

Debugging from the Command Line

To invoke the debugger without modifying any code, use the following command:

wing-debugger-raspbian-5.1.5-1/wingdb yourfile.py arg1 arg2

This is the same thing as python yourfile.py arg1 arg2 but runs your code in Wing's debugger so you can stop at breakpoints and exceptions in the IDE, step through your code, and interact using the Debug Probe in the Tools menu.

By default this runs with python and connects the debugger to localhost:50005, which matches the above ssh tunnel configuration. To change which Python is run, set the environment variable WINGDB_PYTHON:

export WINGDB_PYTHON=/some/other/python

Starting Debug from Python Code

To start debug from within Python code that is already running, edit wing-debugger-raspbian-5.1.5-1/wingdbstub.py and change the line WINGHOME = None to WINGHOME = /home/pi/wing-debugger-raspbian-5.1.5-1 where /home/pi should be replaced with the full path where you unpacked the debugger package earlier. Use pwd to obtain the full path if you don't know what it is.

Copy your edited wingdbstub.py into the same directory as your code and add import wingdbstub to your code. This new line is what initiates debugging and connects back to the IDE through the ssh tunnel.

An alternative to editing wingdbstub.py is to set WINGHOME in the environment instead with a command like export WINGHOME=/home/pi/wing-debugger-raspbian-5.1.5-1.

Further Reading

For additional configuration options and trouble-shooting, see Using Wing IDE with Raspberry Pi.

Use the Tutorial in Wing's Help menu to learn more about the features available in Wing IDE, or take a look at the Wing IDE Quickstart Guide.

More information on Wing IDE can be found in the product overview.

Share this article:






May 06, 2015

Wing IDE Pro has long had the ability to jump to the point of definition of a symbol in source code (press F4 or right-click to select Goto Definition). This works whether or not the symbol is defined in the same file or in an imported module or package.

Similarly, the Find Symbol dialog in the Source menu jumps to symbols anywhere in the current file when you type a fragment that matches its name.

Wing IDE Pro 5.1 takes this a step further by adding a Find Symbol in Project dialog that works the same way but searches all files in the project for matching symbols:

/images/blog/find-symbol/find-symbol.png

When you type a fragment, it can apply anywhere within the symbol name. Multiple fragments separated by spaces can be used to narrow down context as well as symbol name, for example matching class name and then method name:

/images/blog/find-symbol/find-symbol-fragment.png

Find Symbol in Project is very fast, and it is a great way to quickly navigate through hundreds of thousands of lines of code. It is listed in the Source menu, along with the key binding that can be used to display it (Ctrl-Shift-T in most keyboard personalities). If you want to define your own key binding, the command name is find-symbol-in-project.

Share this article:






Mar 31, 2015

Wing IDE Pro's debugger makes it easier to work interactively with Python. In addition to debugging, it is also a great way to navigate and understand unfamiliar code, and to write new code interactively in the live runtime state for which it is being designed.

Debug Probe

The Debug Probe is an important part of Wing's support for interactive development. This is a Python shell that works in the current debug stack frame when the debug process is paused by a breakpoint or exception.

Debug Probe

To use the Debug Probe, set a breakpoint in your code and start debugging from the toolbar icon debug or Debug menu. When you reach the breakpoint or any exception, you can start working interactively in the Debug Probe.

The menus at the top of the Debug Probe are used to select the process, thread, and stack frame you want to work within. Any changes made in the Debug Probe, or side effects of code that is invoked here, are made within the selected stack frame.

The Debug Probe provides auto-completion that is integrated with Wing's Source Assistant, where you can see call signature, documentation, and other information relevant to the code you are typing.

Source Assistant

You can easily jump to point of definition of symbols in the debug probe or their types by pressing F4 or by navigating from the links in the Source Assistant.

Conditional Breakpoints

Conditional breakpoints are handy for isolating a particular case for which new code is being written, giving you direct and convenient access to the actual data being passed to the code that you are working on. Everything you write can immediately be tested against the live runtime state.

Setting a Conditional Breakpoint

To set or edit a conditional breakpoint, right click on the left-most margin in the editor. Breakpoints can also be ignore-counted or enabled/disabled from here, and an overview of breakpoints with statistics is available in the Breakpoints tool in the Tools menu.

Active Ranges

In some cases it's useful to set a range of code in the editor as active in the Debug Probe, in order to make it easier to execute while working on it. This is done with the icons in the upper right corner of the Debug Probe.

Active Range in the Debug Probe

Once an active range is set, it is highlighted in the editor and can be sent to the Debug Probe by pressing the icon in the top right of the Debug Probe or by binding a key to the command debug-probe-evaluate-active-range.

Getting Started with Wing IDE

A quick introduction to Wing IDE's features can be found in our Feature Overview Screencast.

Or just download Wing IDE and give it a try. The Tutorial in Wing's Help menu is a great way to get started.

Share this article:






Mar 20, 2015

Wing IDE Pro's debugger makes is easier to work interactively with Python. In addition to debugging, it is also a great way to navigate and understand unfamiliar code, and to write new code interactively in the live runtime state for which the code is being designed.

Starting with Wing 5.1, multiple debug connections can be made at once, so it is much easier to write and debug multi-process code.

Multi-Process Debugging

Wing 5.1 adds a process selector wherever a stack selector is shown in the user interface, in addition to a thread selector if there are multiple threads in the debug process. The process selector groups processes into a process tree, showing the relationship between them regardless of how they were created or debug-enabled.

Process Selector

When multiple processes are being debugging, pressing the Alt key causes the Debug/Continue, Stop, Restart, and Pause toolbar icons to apply that operation to all the active processes:

/images/blog/multiprocess-debug/toolbar.png

These operations are also in the Debug > Processes menu, along with commands for starting additional new debug processes from the IDE.

Options to control multi-process debugging are in the Debugger > Processes preferences group. For example, you can control when Wing switches to a newly attached debug process and which processes to kill when killing a single debug process.

Multi-Process Debug Preferences

Automatically Debugging Child Processes

Optionally, you can also automatically debug-enable sub-processes created with multiprocessing, via sys.executable, and (on Posix) with os.fork().

Automatically debugging child processes is off by default since it can be confusing or unwanted in some code bases. It can be enabled with the Debugger > Processes > Debug Child Processes preference or (preferably, in most cases) on a project-by-project basis with the Debug/Execute > Debug Child Properties setting in Project Properties.

Enabling Child Process Debugging

This option is useful when working with auto-reloading web application frameworks like Flask or Google App Engine, because Wing will automatically debug the reloaded server processes.

Manually Debugging Child Processes

There are cases where sub- processes cannot be automatically debugged, such as when os.exec() is used (on Posix) or if the process is started without referencing sys.executable. In these cases, the process can still be debugged by importing wingdbstub, which is a module provided by Wing IDE to initiate debugging from outside of the IDE.

In these cases, you will need to enable Accept Debug Connections by clicking on the bug icon in the lower left of Wing's window. This causes Wing to use a fixed port for accepting debug connections. The default matches the port configured wingdbstub.py in your Wing IDE installation.

Details on doing this are in Debugging Externally Launched Code in Wing's reference manual.

Resources

More information can be found in Multi-Process Debugging in the Wing IDE manual.

A quick introduction to Wing IDE's features can be found in our Feature Overview Screencast.

Or just download Wing IDE and give it a try. The Tutorial in Wing's Help menu is a great way to get started.

Share this article:






Mar 11, 2015

Wing IDE Pro's debugger makes is easier to work interactively with Python. In addition to debugging, it is also a great way to navigate and understand unfamiliar code, and to write new code interactively in the live runtime state for which the code is being designed.

A great little feature in Wing's debugger is the ability to move the program counter back to code you have already executed. This way, if you debug too far you can go back without having to restart your debug process.

This is done by right-clicking on the line where you want to move the program counter and selecting Move Program Counter Here:

Move Program Counter

That's all there is to it!

Move Program Counter Result

Note that due to the way Python is implemented, the program counter can only be moved within the current bottom-most stack frame.

To try this out, download Wing now!

Share this article:




Older Articles

2014

Wing IDE 5.0.9 adds the ability to set an active range of code in the editor. This makes it easier to reevaluate edited sections of code in the Python Shell or Debug Probe.   Read more This new screencast takes you on a tour of some of the features in Wing IDE Professional version 5.   Read more How to get the most out of Wing IDE Pro's auto-completer and source assistant for Python.   Read more Learn how to use Wing IDE Pro's advanced auto-editing features to speed up writing and modifying Python code.   Read more

Wingware Blog