wiki:PyGamma

Version 18 (modified by flip, 9 years ago) (diff)

--

PyGAMMA

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, 2.6 and 2.7.

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

Downloading PyGAMMA

You can download the latest stable version of PyGAMMA from here: PyGammaDownloads

Installing PyGAMMA

PyGAMMA uses the standard Python installer setup.py. It attempts to use prebuilt PyGAMMA 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.

Running setup.py

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 setup.py install

And this command on other platforms --

sudo python setup.py install

If setup.py says that it doesn't have binaries for your platform, you'll need to follow the instructions below to build PyGAMMA. If you find yourself in this situation, the pygamma directory from which you just ran setup.py is useless, I'm afraid, so you'd best delete it to avoid confusion.

Building PyGAMMA

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

First you'll need to follow the instructions for downloading the code. Once you've done that, continue with the paragraph below.

You'll need Python, a compiler (see below) and a tool called SWIG. You can install Python and SWIG separately or together. For advice on the latter, 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.)

Prerequsities

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 setup.py can find them. When this process completes, you're ready to run setup.py as explained above.

Building Binaries on Windows

Prerequsities

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 Visual Studio.
  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 setup.py can find them. When this process completes, you're ready to run setup.py 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.

Installing PyGAMMA After a Build

Installing after a build works just the same as if you were using prebuilt binaries. Just follow the instructions on this page under the heading Installing PyGAMMA.

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.

Under Windows, you can run the automated tests from within Visual Studio. Right click on the pytest project and build it to run all the tests in the gamma/trunk/src/pyTests directory.