Trac Broke in Debian After Python 2.5 Became the Default

2008.05.04 21:52

My Trac is broken

A few days ago I tried to log into my local Trac instance but saw “Internal Server Error”.

Looked in /var/log/apache2/error.log and saw:

[error] get_interpreter: no interpreter callback found.
[error] [client 192.168.1.100] python_handler:
  Can't get/create interpreter.
[error] make_obcallback: could not import mod_python.apache.\n
  ImportError: No module named mod_python.apache
[error] make_obcallback: Python path being used
"['/usr/lib/python2.4/site-packages/setuptools-0.6c3-py2.4.egg',
'/usr/lib/python2.4/site-packages/buildutils-0.1.1-py2.4.egg',
'/usr/lib/python2.4/site-packages/4Suite_XML-1.0.2-py2.4-linux-x86_64.egg',
'/usr/lib/python24.zip',
'/usr/lib/python2.4',
'/usr/lib/python2.4/plat-linux2',
'/usr/lib/python2.4/lib-tk',
'/usr/lib/python2.4/lib-dynload',
'/usr/local/lib/python2.4/site-packages',
'/usr/lib/python2.4/site-packages',
'/usr/lib/python2.4/site-packages/Numeric',
'/usr/lib/python2.4/site-packages/PIL',
'/usr/lib/python2.4/site-packages/gst-0.10',
'/var/lib/python-support/python2.4',
'/usr/lib/python2.4/site-packages/gtk-2.0',
'/var/lib/python-support/python2.4/gtk-2.0',
'/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode']".

Ran dpkg -L libapache-mod-python and noticed that some stuff was installed in /usr/lib/python2.5/site-packages. But the log implies that Trac is using Python 2.4?

Wait, which is Debian’s default Python version?

->matth@juggernaut ~ ? type python
python is /usr/bin/python
->matth@juggernaut ~ ? ll /usr/bin/python
lrwxrwxrwx 1 root root 9 2008-05-02 06:35 /usr/bin/python -> python2.5*

Looks like the default switched to 2.5 since that morning’s apt-get upgrade.

Getting Trac running with Python 2.5

I restarted Apache, but then it complained because ClearSilver (Trac’s templating engine) wasn’t installed for Python 2.5.

easy_install ClearSilver failed (”couldn’t find setup file”). Download, configure, make, make install also failed, complained about a C# test failing.

I then read that you can easy_install Trac. I think I would prefer to manage it this way. I apt-get removed it, then easy_installed it.

Trac ran, but complained about not having permissions to write to /var/www/.python-eggs. I created this directory and blessed the permissions.

Trac ran! But my custom header wasn’t there.

The Trac 0.11 Release Notes are informative. They switched their templating engine from ClearSilver to Genshi.

Porting my templates from Clearsilver to Genshi

PortingFromClearSilverToGenshi helps.

I created site.html in $trac_root/templates. ($trac_root is nothing required by Trac, it’s just where I keep my custom Trac scripts and similar things.)

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:py="http://genshi.edgewall.org/"
  py:strip="">

  <head py:match="head" py:attrs="select('@*')">
    ${select('*|comment()|text()')}
    <link rel="stylesheet" type="text/css"
      href="${href.chrome('site/style.css')}" />
  </head>

  <body py:match="body" py:attrs="select('@*')">
    <div id="siteheader" style="margin:1em 0 1em 0;">
      <a href="/">trac root</a>
      /
      <a href="/$project.name">$project.name</a>
      /
      <a href="/$project.name/report/3">active tickets by milestone</a>
    </div>

    ${select('*|text()')}

  </body>
</html>

Then, for each of my Trac project directories, I added this to $project/conf/trac.ini:

[inherit]
templates_dir = /x/system/trac/templates/

(my $trac_root = /x/system/trac)

Good night, and good luck.

Comments? (moderated as hell)

allowed HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>