wiki:PyGamma

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

--

PyGAMMA

PyGAMMA is a Python-wrapped version of GAMMA. It combines the 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++.

PyGAMMA works with Python 2.5, 2.6 and 2.7 (but not the 3.x series).

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

The PyGAMMA wrapper was created using SWIG. Most, but not all of GAMMA is available to Python through PyGAMMA.

We have are some tips on exploring and using PyGAMMA.

The performance of PyGAMMA for compute-intense calculations is very comparable to that of GAMMA.

Downloading PyGAMMA

You can download the latest stable version of PyGAMMA from the PyGammaDownloads page.

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.

Installing a Custom 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.

If you need a custom PyGAMMA, the process to build and install it is quite simple but the setup can take some time. Once the setup is complete, the build and install takes four steps --

  1. Change to the appropriate directory for your platform (e.g. cd ~/gamma/platforms/Linux)
  2. Build (for all non-Windows platforms, make pysgdist)
  3. Change to the pygamma directory (cd ../../pygamma or cd ~/gamma/pygamma)
  4. Run setup.py (python setup.py install or sudo python setup.py install)

These steps and the setup for them are explained in detail below for building PyGAMMA on Windows, Unix and Unix-like platforms.

Building PyGAMMA (All Platforms)

Build Prerequsities (All Platforms)

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

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.

Which Python and/or SWIG?

If you have multiple versions of Python or SWIG installed on the computer where you're building PyGAMMA, be aware that our build process uses the first version it finds in the PATH.

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

Prerequsities (Unix[-Like] Platforms)

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".

If you're not on OS X, you might want to consider installing an optimized linear algebra library before building, although this is not essential. OS X already has such a library installed, and GAMMA takes advantage of it.

The Build (Unix[-Like] Platforms)

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 (Windows)

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

The Build (Windows)

  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 (All Platforms)

Installing after a build works just the same as if you were using prebuilt binaries. Just follow the installation instructions above.

Testing PyGAMMA (All Platforms)

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.