PyXspec  1.0.3
Build and Install PyXspec
Previous: Release Notes Next: A Tutorial - Quick Version


Requirements

Since we do not distribute Python with the HEASOFT packages, you'll need to have it already installed on your system (which it is with most Linux and Mac OSX distributions). PyXspec requires a Python version of 2.x where x is 3 or later. The python executable must be on your path, and with the library and header files located in the standard directories relative to the executable (see the Troubleshooting section for more info).

Building/Installing

PyXspec is fully integrated into the general HEASOFT build procedure, as described at http://heasarc.gsfc.nasa.gov/lheasoft/install.html . So it will be built and installed automatically with the rest of XSPEC/HEASOFT, requiring no additional effort from the user.

Once HEASOFT is finished building and installing, you should find PyXspec's code files and lib_pyXspec.so library in the directory $HEADAS/lib/python/xspec.

When you run the HEASOFT initialization script ($HEADAS/headas-init.csh or .sh), it will add $HEADAS/lib/python to your PYTHONPATH environment. This allows Python find the PyXspec module so that you may load it into your session from anywhere, using the "import xspec" statement.

Running on Mac OS X

These issues apply only to Mac OS X users. Linux users may skip this section.

Case 1: Running the default Xcode distribution of Python (normally /usr/bin/python).

You may use the default Xcode Python if your HEASOFT distribution was built using the Xcode gcc and g++ compilers, with only the Fortran compiler coming from a 3rd party such as Fink or MacPorts. But if you built HEASOFT with ALL of your compilers coming from Fink or MacPorts, you cannot use the Xcode Python (see Case 3).

If your platform is OS X Snow Leopard or later, you must set:

      export VERSIONER_PYTHON_PREFER_32_BIT=yes    # Bourne-like shells      
          or          
      setenv VERSIONER_PYTHON_PREFER_32_BIT yes    # C-like shells

BEFORE importing the xspec module into Python.

Case 2: Running a Python distribution obtained from www.python.org.

If you're using a recent distribution from www.python.org (Python 2.7 or later) on Snow Leopard, you'll need to ensure that you run the 32-bit version, and the method used in Case 1 will not work. Instead, invoke 32-bit Python by way of the arch command. For example:

      arch -i386 python2.7

Case 3: Running the Fink or MacPorts Python.

This applies only to users who have built HEASOFT using Fink or MacPorts for ALL 3 of their compilers (gcc, g++, gfortran). Note that you can avoid all of this if you build HEASOFT using Mac's own Xcode gcc and g++, and only use Fink or MacPorts for gfortran.

You are going to have to get the corresponding Fink or MacPorts distribution of Python for both building and running PyXspec. The standard Xcode Python (in /usr/bin) will conflict with libraries pulled in by the Fink and MacPorts gcc.

To rebuild PyXspec using the Fink or MacPorts Python, first edit the file heasoft-<ver>/Xspec/src/XSUser/Python/xspec/Makefile by adding definitions for PYTHON_INC and PYTHON_LIB that point to your Fink or Mac Python header and library files. For example if using the Fink Python v2.6 in its default location, you would insert the following in your Makefile, after the definition for HD_LIBRARY_ROOT and before the definition for HD_CXXFLAGS:

PYTHON_INC = /sw/include/python2.6
PYTHON_LIB = -L/sw/lib/python2.6/config # Note that this must begin with '-L'

Then from the same directory containing the Makefile, do:

hmake clean
hmake
hmake install

Troubleshooting

If the HEASOFT configuration stage fails when it's processing PyXspec, it will just issue a warning and continue. Its failure should not affect the rest of the XSPEC and HEASOFT build. Standard XSPEC will still be fully functional, but its Python interface won't be available.

The most likely cause of a PyXspec build failure is that the HEASOFT configuration script can't find a python executable and/or its accompanying library and header files. You should first check that the command "which python" can find an executable on your path. The configuration script first looks for python, which is normally a symbolic link to the version-specific executable. If it doesn't find that, it looks for python2.7 down to python2.3 in descending order.

Once it's found an executable, it looks for Python.h and libpython[m.n].so (or .dylib) in the directories ../include/python[m.n] and ../lib respectively, relative to the executable location. The configuration fails if either file is missing.

If you are running on Mac OS X Snow Leopard and get a Python "ImportError" message containing such statements as no suitable image found and mach-o, but wrong architecture, you need to ensure that you are running the 32-bit version of Python. See Case 1 and Case 2 in the previous section for how to do this.

If you are running on a Mac and have built your HEASOFT installation with all 3 compilers (gcc, g++, gfortran) coming from Fink or MacPorts, AND you get a runtime error that begins with something like:

python(86419) malloc: *** error for object 0x574b160: pointer being freed was not allocated

then it likely means there's a conflict between your default Python distribution and the compiler libraries used to build PyXspec. Please see Case 3 in the previous section for how to rebuild PyXspec with a Fink or MacPort distribution of Python.