Sage and PyQt4

I wanted to use Qt4 as a backend for Sage’s matplotlib.  This wasn’t as hard as I thought it was going to be.  This “all done for you” systems always leave me stymied when I want to do something.  Sage had some really nice surprises (dare I say gifts) in this regard.

The basic steps for installing your favorite Python package into Sage seems to be:

  1. Pull down the package
  2. Unextract it (e.g. tar -xzf <package.tgz>
  3. Create an spkg (sage pkg) by writing a spkg-install and tarring it up with a spkg extension.
  4. Installing the spkg by running `sage -i <package>.spkg`
  5. Dropping into sage sh to fix whatever goes wrong (following the instruction spit out by sage when the installation fails).

To get started, I installed the latest Sage.  I unpacked this into a local directory and made a soft link to the sage executable.

I then pulled down PyQt and sip from Riverbank.  I unpacked these in a local directory.  For both packages, I did the following:


mv packagedir src
mkdir packagedir
mv src packagedir/
cd packagedir
cat > spkg-install
#!/bin/sh
cd src
# Now build and install.
python configure.py
make
make install
if [ $? -ne 0 ]; then
echo "Error building PyQt4."
exit 1
fi
^D
cd ..
tar -cvf package.spkg packagedir

Then I ran sage -i for the sip package and this went perfectly.  The PyQt had issues because I have both Qt3 and Qt4 installed on my system.  Following the cool sage install output I dropped into the sage -sh shell and manually ran the steps in the PyQt’s spkg-install script.  Specifically, I had to run the pythong configure.py with the -q <path to Qt4 qmake> and the -g option (something to do about libraries).

sage -pylab works for normal plotting.  However, it barfs for function plotting e.g plot([sin,cos]).  Sigh.  Guess that is why they don’t use it.