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.
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.
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.6-1.tgz. This creates a directory named wing-debugger-raspbian-5.1.6-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.6-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
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.
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.
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.
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:
Plug in the USB wifi card and reboot your Raspberry Pi
Edit /etc/network/interfaces and comment out the interface for wlan1. Nothing works if this is not done.
Edit /etc/wpa_supplicant/wpa_supplicant.conf and add the following to the end:
network={ ssid="<yourssid>" scan_ssid=1 key_mgmt=WPA-PSK psk="<yourpassphrase>" }
Replace <yourssid> your wifi network name and <yourpassphrase> with your wifi passphrase. Be sure to use exactly the above with no changes in spacing and with the quotes for the ssid and passphrase but not for other things. Otherwise nothing works and you won't get any usable error messages.
Restart your Raspberry Pi again and wifi should work.