python

Python
[|Python] is a wonderfully clean interpreted programming language with remarkable power and flexibility. The sample projects for this course make heavy use of the language, and we encourage you to do the same.

Contents
Getting Python Documentation Helpful Modules CherryPy NumPy pySerial py-appscript SWIG Extension

Getting Python
We highly recommend [|version 2.7.2]. Python's newer 3.x branch is not backwards-compatible; use at your own risk. The one module essential to your project always seems to be the one not yet ported to Python 3. Additional headache reducer: download the **32-bit** build, regardless of your system architecture. Much to our frustration, some closed-source packages provide only 32-bit binaries. Download and run the installer. Tip: Install to the default location, even though it's a little funky ("C:\Python27\").
 * Windows**

Apple's preinstalled Python builds are generally outdated, so you may wish to update. Use the combined 32/64-bit installer, unless you're somehow still on a PowerPC processor.
 * Mac OS X**

Nearly every Linux distribution includes Python 2.7.2--some even provide the 3.x branch as well. If not, check your package repository before building from source.
 * Linux**

Documentation
Though many of you are already expert Pythonists, we've provided these links just in case.
 * [|Officlal Documentation]**

These docs speak for themselves: tutorials and language/library references.
 * [|Python Setup and Usage]**

In-depth instructions for getting Python up and running on a variety of platforms.

Helpful Modules
We've found these modules to be very helpful in developing our programs--install as needed.

CherryPy
[|CherryPy] is a nifty web framework and server designed for simplicity and speed. It's great for building web applications that do more than serve up webpages--we've used it for remote control of our Roombot. URLs get mapped directly to Python functions, and your code takes it from there.

easy_install cherrypy
 * Installation: All Platforms**

[|CherryPy Tutorial] [|Current Documentation] [| Legacy Documentation] (more helpful) Sample Project: Roombot
 * Documentation**

NumPy
[|NumPy] greatly bolsters Python's computational ability. Think MATLAB for Python--especially when combined with sister project SciPy. We use NumPy for its exceptionally fast dimensional arrays, which enable Python to handle image data from the XBox Kinect with reasonable speed. The current stable release is [|version 1.6.0].

Download and run the [|appropriate binary] for your platform and Python version.
 * Installation: Windows and Mac OS X**

Installation: Linux Most distributions provide unofficial packages; official builds are available for Ubuntu. The [|installation instructions] have more information.

Documentation [|Detailed Installation Instructions] [|Getting Started] [|Numpy Tutorial] Sample Project: Blender Kinect

pySerial
[|pySerial] is the //de facto// standard Python module for interfacing with serial devices. Works out-of-the-box with Windows, Mac OS X, and Linux. [|Version 2.5] is compatible with all recent releases of the 2.x and 3.x branches. easy_insta​ll -U pyserial View more [|detailed installation instructions]. [|Official Introduction] Sample Project: Roombot
 * Installation: All Platforms**
 * Documentation**

py-appscript
[|py-appscript] is a Python bridge to [|AppleScript], Mac OS X's built-in scripting language for automation. The module gives Python control over other applications--think opening and printing a PDF through Preview. Support is obviously limited to Mac OS X; Windows and Linux do not provide OS-level automation support.

easy_install -U appscript Note: setuptools unfortunately builds appscript from source using the gcc compiler. For whatever reason, Mac OS X does not ship with gcc, but it is bundled with the XCode developer tools. XCode 4.2 can be purchased from the Mac App Store for $4.99; free, older versions are available on the [|Apple Developer website] or on your OS Install DVD.
 * Installation: Mac OS X**

[|Detailed Installation Instructions] [|Official Docs] Sample Project: Roombot
 * Documentation**

The documentation is excessively technical and rather unhelpful. For small projects, write your script first using AppleScript and Mac OS X's Script Editor, then convert it to Python. The syntax of appscript is quite intuitive (even if the documentation isn't) and follows naturally from associated AppleScript calls.
 * Tip**

SWIG Extension
The [|Simplified Wrapper and Interface Generator] (SWIG) does exactly what it says on the box: it simplifies writing code to interface between Python and C/C++. Python's very own interpreter is written in C, and the language exposes a number of useful APIs. (Python documentation includes an [|extensive tutorial] on manually creating a C++ extension.) In most cases, each C function must be wrapped individually.

SWIG attempts--usually very successfully--to automate the process. Create a small "interface" file which can be used to correct any mistakes, and SWIG generates the rest of the wrapper. The OpenNI sample project uses SWIG to allow Python to interface with the Kinect; check out the code for details.

Download the latest version of [|swigwin]. Note that there is **no installer;** simply extract the zip to a folder. The swig.exe executable has been prebuilt.
 * Installation: Windows**

macswig has been long discontinued, though standard swig //should// work. Follow Linux instructions for building from source,
 * Installation: Mac OS X**

Most distributions provide a **swig** package. If not, you'll need to [|download swig] and compile from source by following the [|README].
 * Installation: Linux**

[|Official Docs] [|Interfacing C/C++ and Python with SWIG Presentation] Sample Project: Blender Kinect
 * Documentation**