Installing SWIG python bindings for subversion, trac

I have a CentOS 5 machine running Apache 2.2, python 2.5, subversion 1.5.2, and trac 0.11. Originally, the machine came with Python 2.4 and SVN 1.4.2 with the SWIG python bindings:

  python2.4 -c "import svn.repos, sys; print svn.repos.__file__; print sys.version"
  2.4.3 (#1, Mar 14 2007, 18:51:08)
  [GCC 4.1.1 20070105 (Red Hat 4.1.1-52)]

After installing Python 2.5 and SVN 1.5.2, I have lost the SWIG python bindings:

  python -c "import svn.repos, sys; print svn.repos.__file__; print sys.version"
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  ImportError: No module named svn.repos

I don't understand this. I installed python 2.5 first, then SVN 1.5.2. Why would SVN put the python bindings into the python 2.4 site-packages area?


Trac requires the SWIG python bindings to work. I need to simple, step-by-step instructions on how to get SWIG python bindings installed into the installed python 2.5 site-packages area for an installed subversion package.

Bonus point for any advice on getting mod_python and mod_dav_svn installed as well. I've actually downloaded and configured mod_python for python 2.5, I just haven't run 'make install' yet because I don't know if it's going to mess with my running apache or not.

Who is Participating?
urgollConnect With a Mentor Commented:
You said: I installed httpd-devel, SVN 1.5.2 and SWIG 1.3.3 using webmin's rpm package installer

Are those RPM from CentOS or from a 3rd party ? The issue here is swig. Swig needs to be compiled against a specific version of python. As long as you are using swig as provided by CentOS5, it is compiled against python 2.4, since this is what CentOS5 provides.

Since you compiled python 2.5 manually, you also need to compile swig manually and tel it where to find python (if 2.5 is not /usr/bin/python).

After that is done, you also need to compile svn 1.5 yourself, since it needs to be compiled against your new swig and python libraries.

Hope this helps.
the location of the installed swig bindings is determined by swig, not subversion. Most likely, the swig you have was compiled against python 2.4, and therefore is configured to put the bindings into the python 2.4 directory.

After upgrading python to 2.5, you may have to upgrade (or at least recompile) swig to match your new python setup.

I have very little experience with mod_python, but mod_dav_svn is fairly easy. All you have to do when compiling subversion is add this to the ./configure line:
assuming the apache apxs binary is in your path.
Then when you 'make install' subversion, the mod_dav_svn will be copied to apache's module directory.
rsgallowayAuthor Commented:
Ok, I upgraded SWIG to 1.3.35, but all it did was put a bunch of stuff here:


What does that mean? Do I need to download and install the source tarball and do a custom configuration instead? Then run a make swig-py? What are the specific steps to create the SVN python bindings?

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Of all the software we're talking about (apache, swig, python, svn) which came with CentOS and which did you compile and install manually ?

Did you update swig using yum (centos package) or manually ?
rsgallowayAuthor Commented:
Apache 2.2, SWIG, Python 2.4 and SVN 1.4.2 came with the CentOS 5 box.

I installed httpd-devel, SVN 1.5.2 and SWIG 1.3.3 using webmin's rpm package installer, and mod_python, trac 0.11 and Python 2.5 I compiled manually.

yum is offline after I installed Python 2.5. I don't know how to get that working again either, but that's a separate issue.
rsgallowayAuthor Commented:
Okay, I was afraid of something like that.

The httpd-devel RPM (and associated dependencies) are from CentOS, I believe. The rest are not.

So basically, I need to

1) recompile SWIG with some option like, --with-python=/path/to/python
2) recompile SVN (hoping it will pick up the new SWIG stuff)

Can I do that using the RPMs? Or do I need to download the sources for both of those? Won't it complain that I already have SVN and SWIG installed? Is there a way to UNinstall packages like SVN/SWIG?
You can remove packages easily, using the rpm command. For example, to remove the SWIG package, you would do:
#  rpm -e swig

Assuming that your python 2.5 is now the default /usr/bin/pyhon on your system, you can do this with RPMs. All you need to do is get the source rpm file (.src.rpm) from the CentOS mirror, and recompile it. This is done with:
#  rpmbuild -bb package.src.rpm
(replace 'package.src.rpm' with the actual source package file name)
It is possible that some -devel packages will be missing, just install those.
The rpmbuild command will compile the package and place it in the /usr/src/redhat/i386 directory (or similar, depending on your computer's architcture). You can then use 'rpm -i package.rpm' to installl it.

So, still assuming that your python 2.5 is the default, you can do:
* remove original svn package
* remove original SWIG package
* rebuild SWIG from source RPM
* install new SWIG rpm
* rebuild SVN from source RPM
* install new SVN rpms

If your python 2.5 is NOT the default /usr/bin/python, then you cannot use the source rpm, as you need to provide the argument '--with-python=/path/to/python' on the ./configure command when building SWIG. However, you should still be able to use the source RPM for SVN.

One BIG not of caution here: you need to keep track of the packages you rebuild, as you must not apply any CentOS-provided upgrade for those packages, as they would revert to using python 2.4 and would break your TRAC installation.

Please let me know how it goes and if you have any further problem.

rsgallowayAuthor Commented:
Making progress. I removed the SWIG and SVN packages, downloaded the source tarballs for each, and installed them.

Output from SWIG config:

checking for Python prefix... /usr/local
checking for Python exec-prefix... /usr/local
checking for Python version... python2.5
checking for Python lib dir... lib
checking for Python header files... -I/usr/local/include/python2.5 -I/usr/local/lib/python2.5/config
checking for Python library... /usr/local/lib/python2.5/config
and the make install put a bunch of stuff here:

Installing /usr/local/share/swig/1.3.36/python/
The SVN config did find python 2.5 and the SWIG bindings:

checking for python... /usr/local/bin/python
configure: Configuring python swig binding
checking for Python includes... -I/usr/local/include/python2.5
checking for compiling Python extensions... gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC
checking for linking Python extensions... gcc -pthread -shared
checking for linking Python libraries...
although there was this:

checking swig version... 1.3.36
configure: WARNING: Detected SWIG version 1.3.36
configure: WARNING: Subversion requires 1.3.24 or later, and is known to work
configure: WARNING: with versions up to 1.3.31
However, the words python or swig did not appear once in the SVN make install output, which seems odd. I would have expected to see something about installing into the python2.5 site-packages area. Also, I still can't import the svn package in python 2.5.

Is there another package I need to download and install? Or, did I leave something out of the SVN ./configure?

rsgallowayAuthor Commented:

I ran these three commands in the SVN source folder:

make swig-py
make check-swig-py
make install-swig-py
and they all completed without error, which is great. I didn't know anything about these commands until a google search. Anyway, it put the SVN python bindings here:

which is not where I wanted them, but I guess there are options for that using LIBDIR or LD_LIBRARY_PATH or something. Not really sure how to use those, so I just made a sym link in the python 2.5 site-packages area to the svn libs and it works. I can import svn in python 2.5 now. Unfortunately, it still doens't fix my trac problem. I'm still getting this error:

Unsupported version control system "svn". Check that the Python support libraries for "svn" are correctly installed.
Do I need to recompile trac or something now? Anyone know?

Are you using TRAC as a CGI or with mod_python ? You need to make sure that TRAC is using python 2.5, not 2.4. If using as CGI, look at the first line of cgi-bin/trac.cgi. If using mod_python, it depends on the version of python mod_python was compiled against.

I haven't used TRAC in a while, but you may have to re-install it. During the installation, the python code is bytecode-compiled, which may or may not be compatible from 2.4 to 2.5, and it probably stores properties such as the location of python.

Just to let you know I'll be out of network access tonight and tomorrow, but will look up this thread tomorrow night see if you've made progress and if I can conjure up some more advise.

Have a great week-end,
rsgallowayAuthor Commented:
Thanks for the information.

I'm actually running trac with the trac server: tracd, at least until I reinstall mod_python. I have recompiled mod_python with python 2.5, but have not run the make install yet because I was nervous it might break something. I have live sites deployed and no dev/test server. So the tracd server is using python2.5, no doubt.

It's funny because I set up a new trac project and svn repo and that syncs up fine. I just get that error on an existing trac project, so maybe it's a trac project config issue. I will keep playing with it. Thanks for the help, urgoll.
rsgallowayAuthor Commented:
Ok, got it! Finally. I just needed to restart the trac daemon to pick up the python svn bindings. Makes sense. Thanks!
Good, I'm glad it works for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.