Note

"Within a couple of minutes I could fence in and eliminate an error with the handling of a GPRS modem attached to the Raspberry Pi that before I was trying to hunt down for hours." -- Robert Rottermann, redCOR AG

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.

For more information on Wing IDE see the product overview. If you do not already have Wing IDE installed, download a free trial now.

To get started using Wing, refer to the tutorial in the Help menu in Wing and/or the Wing IDE Quickstart Guide.

Introduction

The Raspberry Pi is not currently 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 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 from the machine running Wing IDE and the Raspberry Pi.

The easiest way to connect the Raspberry Pi to your network is with ethernet, or see the instructions at the end of this document 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:

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.6-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 configuration. To change which Python is run, set the environment variable WINGDB_PYTHON:

export WINGDB_PYTHON=/some/other/python

Use the Tutorial in Wing's Help menu to learn more about the features available in Wing IDE.

Starting Debug from Python Code

To start debug from within Python code that is already running, edit wing-debugger-raspbian-5.1.6-1/wingdbstub.py and change the line WINGHOME = None to WINGHOME = /home/pi/wing-debugger-raspbian-5.1.6-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.6-1.

Configuration Details

If for some reason you can't use port 50005 as the debug port on either machine, this can be changed on the Raspberry Pi with kHostPort in wingdbstub.py or with the WINGDB_HOSTPORT environment variable. To change the port the IDE is listening on, use the Debugger > External/Remote > Server Port preference and or Debug Server Port in Project Properties in Wing IDE.

If this is done, you will need to replace the port numbers in the ssh tunnel invocation in the following form:

ssh -N -R <remote_port>:localhost:<ide_port> <user>@<rasp_ip>

The first port number is the port specified in kHostPort or with WINGDB_HOSTPORT environment variable, and the second one is the port set in Wing IDE's preferences or Project Properties.

On Windows using PuTTY, the Source port is the port set with kHostPort or WINGDB_HOSTPORT on the Raspberry Pi, and the port in the Destination is the port Wing is configured to listen on.

Refer to the documentation for ssh or PuTTY for details.

Trouble-Shooting

There are several ways in which a debug configuration can fail and when a connection cannot be established to the IDE code will run without debug. Additional diagnostic output is needed to find the cause of most problems. This is done by setting an extra environment variable before initiating debug on the Raspberry Pi:

export WINGDB_LOGFILE=/home/pi/debug.log

Hovering the mouse over the bug icon in the lower left of Wing's window will show if a debug connection is active. Wing also adds icons to the toolbar while debugging.

If Wing is not receiving a connection, check the reverse ssh tunnel, make sure that wingdebugpw was copied, and check that Wing is listening for debug connections.

If Wing is receiving a connection but breakpoints are not reached or source code is not shown when reaching an exception, check your location map preference. A good way to test this is to add a deliberate unhandled exception to your code (such as assert 0) to see if Wing's debugger stops but fails to show the source code. The location map must be correct for Wing to show the source code.

Setting up Wifi on a Raspberry Pi

It is possible to easily and cheaply connect a Raspberry Pi 2 to a wifi network. Here are instructions for doing this using an Edimax EW-7811Un wifi USB card (although other cards may also work) for a passphrase-protected wifi network: