Go Premium for a chance to win a PS4. Enter to Win


Installing SWIG python bindings for subversion, trac

Posted on 2008-10-02
Medium Priority
Last Modified: 2013-12-06

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.

Question by:rsgalloway
  • 7
  • 6

Expert Comment

ID: 22630590
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.

Author Comment

ID: 22630772
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?


Expert Comment

ID: 22634564
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 ?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 22635078
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.

Accepted Solution

urgoll earned 1000 total points
ID: 22635131
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.

Author Comment

ID: 22635268
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?

Expert Comment

ID: 22640940
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.


Author Comment

ID: 22642036
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?


Author Comment

ID: 22642119

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?


Expert Comment

ID: 22642183
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,

Author Comment

ID: 22642207
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.

Author Comment

ID: 22642559
Ok, got it! Finally. I just needed to restart the trac daemon to pick up the python svn bindings. Makes sense. Thanks!

Expert Comment

ID: 22649798
Good, I'm glad it works for you.


Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question