Installing Google App Engine Python SDK in Slackware

Currently, Slackware 13.37 RC2 has Python 2.6.6 and Google’s App Engine SDK for Python requires Python 2.5.x. After several days of contemplation, I decided to give it a try and installed Python 2.5.5 in parallel with Slackware’s stock Python.

Multiple Python

Since Google’s App Engine SDK for Python requires or at least more safe when using Python 2.5.x, I have no choice but to install one. While learning Python in general, I also need the latest stock Python from Slackware since other applications uses it like Frozen Bubble game. I will install the version 2.5.5 somewhere in /opt leaving the original Python intact.

We can download Python 2.5.5 source from Python’s website.

Building Custom Python

In Slackware, it is fairly easy to build any supported software however, there is so-called the Slackware way of building packages via Slackbuilds. Let’s call it Slackbuilding. The art of Slackbuilding includes a Slackbuild script that sets at a build environment, configure the source and creates a Slackware package.

To make things easy, I look for the Python Slackbuild script from Slackware 12.2 source tree and modifies it a bit since it is for Python 2.5.2 and also contains several security patches. Python 2.5.5 is somewhat like the last release for 2.5.x series so it needs no patch of whatsoever.

Let’s Build It

Enough for the overview and let’s get to work. First get the Python 2.5.5 source code from the Python’s website and put it somewhere, for example: ~/python-2.5.5. On the same directory, create this Slackbuild script. Below is a Python Slackbuild script derived from Slackware 12.2 source with minor modifications.

#!/bin/bash
CWD=`pwd`
TMP=${TMP:-/tmp}
PKG=$TMP/package-python
rm -rf $PKG
mkdir -p $PKG

VERSION=2.5.5
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}

# Location for Python site-packages:
SITEPK=$PKG/usr/lib/python2.5/site-packages
# same as above without $PKG
TOOLSDIR=/usr/lib/python2.5/site-packages

# Normally I don't trust -O3, but it is the Python default so
# I'll assume that in this case it has been well tested.
if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O3 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O3 -march=i486 -mtune=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O3"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O3"
fi

cd $TMP
rm -rf Python-$VERSION
tar xvzf $CWD/Python-$VERSION.tgz || exit 1

cd Python-$VERSION

# Security patches:
#zcat $CWD/patches/CVE-2008-1679-1721.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1
#zcat $CWD/patches/CVE-2008-3144.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1
#zcat $CWD/patches/CVE-2008-3142.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1
#zcat $CWD/patches/CVE-2008-2316.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1
#zcat $CWD/patches/CVE-2008-2315.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1

# Clean up after the patches:
#find . -name "*.orig" -exec rm "{}" \;

chown -R root:root .
find . -type d -exec chmod 755 {} \;
find . -type f -perm 775 -exec chmod 755 {} \;
find . -type f -perm 664 -exec chmod 644 {} \;
find . -type d -name CVS -exec rm -r {} \;

OPT="$SLKCFLAGS" \
./configure \
  --prefix=/opt/python-2.5 \
  --mandir=/opt/man-python-2.5 \
  --with-ncurses \
  --with-threads \
  --enable-ipv6 \
  --enable-shared \
  --build=$ARCH-slackware-linux

make -j4 || exit 1
make install DESTDIR=$PKG

# Install some python-demo files:
mkdir -p $PKG/usr/doc/python-$VERSION
cp -a Demo $PKG/usr/doc/python-$VERSION

# We'll install the python-tools under site-packages:
mkdir -p $SITEPK
( cd Tools ; cp -a * $SITEPK )
mkdir -p $PKG/usr/doc/python-$VERSION
mv $SITEPK/README $PKG/usr/doc/python-$VERSION/README.python-tools
( cd $PKG/usr/doc/python-$VERSION
  ln -sf $TOOLSDIR Tools
)
# Make a few useful symlinks:
mkdir -p $PKG/usr/bin
( cd $PKG/usr/bin
  ln -sf $TOOLSDIR/modulator/modulator.py modulator
  ln -sf $TOOLSDIR/pynche/pynche pynche
  ln -sf $TOOLSDIR/i18n/msgfmt.py .
  ln -sf $TOOLSDIR/i18n/pygettext.py .
)

# Install docs:
mkdir -p $PKG/usr/doc/python-$VERSION
cp -a README $PKG/usr/doc/python-$VERSION
cp -a Misc $PKG/usr/doc/python-$VERSION
( cd $PKG/usr/doc/python-$VERSION ; mkdir html )
( cd $PKG/usr/doc/python-$VERSION/html
  tar xjvf $CWD/html-$VERSION.tar.bz2
  chown -R root:root .
)
( cd $PKG/usr/bin
  rm -f python
  ln -sf python2.5 python
)
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
gzip -9 $PKG/usr/man/man1/*.?
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n $TMP/python-$VERSION-$ARCH-$BUILD.tgz

Modifications are the following:

  1. Version is changed to 2.5.5
  2. Build is changed to 1
  3. Extracting the source from bz2 changes to tgz (tar xvzf)
  4. Commented out the patch lines since there are no patch to apply on stable version
  5. Configure options modified:
    1. –prefix=/opt/python-2.5 \
    2. –mandir=/opt/man-python-2.5 \

Save it on the directory where you copied the source code and name it python.SlackBuild. Be sure to put an execute bit by invoking chmod +x python.SlackBuild.

Be sure to create first /opt/man-python-2.5.

To run the Slackbuild script, on the current directory, run: ./python.SlackBuild as root. It will take several minutes.

Post Build

After several minutes of the build process, it must have created a Slackware package in /tmp/python-2.5.5-i486-1.tgz. When you install that in Slackware, there are still chances that it will override some stock Python files. That is because there is an install script doinst.sh in the resulting Slackware package that overrides some Python related files.

What we need is to modify /tmp/python-2.5.5-i486-1.tgz and repackage again. Copy the package somewhere, example: ~/python-install and extract the contents.

tar xvzf python-2.5.5-i486-1.tgz

What I did is extract them into ~/python-install/python-modified which now contains the following directories:

  • install
  • opt
  • usr

Inside ~/python-install/python-modified/install, I edited doinst.sh so that it will contain the following:

( cd usr/doc/python-2.5.5 ; rm -rf Tools )
( cd usr/doc/python-2.5.5 ; ln -sf /usr/lib/python2.5/site-packages Tools )
( cd opt/python-2.5/lib ; rm -rf libpython2.5.so )
( cd opt/python-2.5/lib ; ln -sf libpython2.5.so.1.0 libpython2.5.so )
( cd opt/python-2.5/bin ; rm -rf python-config )
( cd opt/python-2.5/bin ; ln -sf python2.5-config python-config )

What I just did was to remove some copying of files directly to /usr directory where it may override existing python binaries.

Finally, to create the final safe package, we need to cd to ~/python-install/python-modified and run the following command as root:

makepkg -l y -c n ../python-2.5.5-i486-1.tgz

which effectively repackaged it into a new Slackware package with custom install script and saves it to the parent directory. Finally, we now have ~/python-install/python-2.5.5-i486-1.tgz which is safe to install in our Slackware 13.37 (leet edition).

To install it, execute:

installpkg ~/python-install/python-2.5.5-i486-1.tgz

Please note that all filenames mentioned above may not work when you follow step by step (not unless you login as root from the start). Adjust paths, versions and filenames accordingly.

What about the shared libraries

When you run your newly installed Python 2.5.5 (ex: /opt/python-2.5/bin/python –version), it will fail to load some shared libraries since our libraries are not installed on the shared library path. We need to add /opt/python-2.5/lib to lib path by editing /etc/ld.so.conf and add this line at the end:

/opt/python-2.5/lib

and run ldconfig. You can now check Pyhon by running:

/opt/python-2.5/bin/python –version

and it should say the correct version (2.5.5).

Time for the Google App Engine SDK for Python

Just get the Google App Engine SDK for python for Linux which is a zipped file. Extract it to the location you want to install it. I installed (extracted and renamed) them into /opt/google-appengine so that dev_appserver.py will be located at /opt/google-appengine/dev_appserver.py.

Assuming you have an App Engine project at /var/www/htdocs/helloworld, we can run it on localhost:8080 by running:

cd /opt/google-appengine
/opt/python-2.5/bin/python dev_appserver.py –skip_update_sdk_check /var/www/htdocs/helloworld

Screenies

Here are some screenshots.







This entry was posted in AppEngine, Python, Slackware. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *