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


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


PyXspec is fully integrated into the general HEASOFT build procedure, as described at . 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 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.

Beginning with HEASoft-6.16, Mac builds are 64-bit by default. Therefore if you have a default build, you should no longer run Python in 32-bit mode.

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

HEASoft builds on Macs are now 64-bit by default. However if (and only if) you forced your build into 32-bit mode by configuring with --enable-mac_32bit_build=yes, you will need to set:

      export VERSIONER_PYTHON_PREFER_32_BIT=yes    # Bourne-like shells      
      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

If (and only if) you forced your HEASoft build into 32-bit mode, you'll need to ensure that you run the 32-bit Python 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 install


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 and get a Python "ImportError" message containing such statements as no suitable image found and mach-o, but wrong architecture, it's likely you are running 32-bit mode Python while your default HEASoft build is now 64-bit. Make sure you are NOT still using the settings in Case 1 and 2 above for running 32-bit Python.

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.