Version 4 (modified by flip, 10 years ago) (diff)



PyGAMMA is a Python-wrapped version of GAMMA. It combines the full power of the GAMMA library with the convenience of working in the Python programming language. Python is open source, object-oriented, and considerably easier to write than C++. The performance of PyGAMMA is slightly reduced relative to native GAMMA.

PyGAMMA works with Python 2.5 and 2.6.

The main GAMMA build page has some advice on picking a Python version if you don't have one installed already.

Installing PyGAMMA

PyGAMMA uses the standard Python installer You can find in the pygamma directory. It attempts to use prebuilt GAMMA binaries for your platform. If it can't find appropriate binaries, it will tell you that and direct you to the instructions below for making your own.


If you've installed Python applications before, this might seem familiar. At the command line, in gamma/pygamma directory, execute this command under Windows --

python install

And this command on other platforms --

sudo python install

If says that it doesn't have binaries for your platform, you'll need to follow the instructions below.

Building Binaries

While we'd like to provide prebuilt binaries for every platform, that's not practical given the variety of operating systems, Python versions and architectures (32/64 bit) out there. Some of you will have to build the PyGAMMA binaries yourself.

There are instructions below for building PyGAMMA on Windows and on Unix and Unix-like platforms.

Build Prerequsities

You'll need Python, a compiler (see below) and a tool called SWIG. For advice on downloading Python and SWIG together, see the main GAMMA build page. We've had success with SWIG versions 1.3 through 2.0.

Building Binaries on Unix[-Like] Platforms (OS X, Linux, etc.)


In addition to Python and SWIG, you'll need the gcc compiler. This build should work with any 4.x version of gcc.

Under OS X, download the XCode/Developer Tools package to get make and gcc.

Linux users, in addition to gcc, you might need to install the development package for your version of Python. If the build complains that Python.h is missing, you need to install a package called something like "python-dev".

The Build

Once you have the prerequisites installed, go to a command line and then change to the gamma/platforms directory. Once there, change into the subdirectory appropriate for your platform. Then, execute this command --

make pysgdist

That will build PyGAMMA and place the relevant build output files in a place where can find them. When this process completes, you're ready to run as explained above.

Building Binaries on Windows


In addition to Python and SWIG, you'll need the free C++ compiler Visual Studio 2008 Express Edition.

The Build

  1. Find the file /gamma/platforms/msvc2008e/dynamic/gamma.sln and double click on it to open MSVC.
  2. Ensure that python.exe is in your PATH.
  3. Either ensure that swig.exe is in your PATH, or edit the build properties to supply an explicit path to swig.exe on your machine.

If you opt for the latter, open the Visual Studio Project-->Properties menu. Then select Configuration Properties --> Build Events --> Pre-Build Events and then edit the Command Line property. Change "swig" to an explicit path. The result will look something like this:

"C:\Program Files\swigwin-2.0.0\swig.exe" -c++ -python -outdir ..\..\i686-pc-msvc  -I..\..\src -o ..\..\i686-pc-msvc\pygamma_wrap.cxx pygamma.i
  1. Hit F7 to start the build.

The steps above will build PyGAMMA and place the relevant build output files in a place where can find them. When this process completes, you're ready to run as explained above.

Potential Windows Build Problems

The build may fail if built in debug mode due to a SWIG quirk and the lack of Python debug library. If you get an error like this --

LINK : fatal error LNK1104: cannot open file 'python25_d.lib'

You can work around this by building PyGAMMA in Release mode. In Visual Studio at the top of the screen, just beneath the menus, you can find a drop down that offers a choice between Release and Debug. Alternatively, you can select the Build-->Configuration Manager menu item. Visual Studio will display the Configuration Manager dialog. Under Active Solution Configuration, select Release. Close the dialog and rebuild.

Testing PyGAMMA

Once PyGAMMA is installed, you can run an automated test under any Unix-like operating system from the command line. Change directory to gamma/platforms and then move into the appropriate platform (Linux, OSX, etc.). From there, execute make pytest.

This runs the tests in gamma/src/pyTest. You can also run the .py files there manually.