Saved for later reference

online repository of stuff I had to google for hours to figure out

Compiling Subversion Python bindings on Windows

Tags: , , , , , ,

I tried finding good instructions on building the Python SVN bindings (for use with Trac), but the included readme file is based on Visual C++ 5.0/6.0 (which I remember using back in ’98), and leaves out a few crucial steps.

So, this how-to will explain the process of building SVN bindings for Python 2.6 on Windows.

What you’ll need:

  • Visual C# 2008 Express Edition (Visual Studio 2008 will also work, but will base this on free downloads)
  • Swig (I used swigwin-1.3.39 specifically, but any newer version should do)
  • Subversion source – grab both the source file subversion-1.6.0.zip and the dependencies subversion-deps-1.6.0.zip

Preparing

Start with installing VC++ 2008 Express and Python if you haven’t already, then create a folder to store the source trees (I used C:\Temp – and will use that folder in the instructions here for simplicity). Unpack Swig to C:\Temp\swig, and subversion-1.6.0.zip and subversion-deps-1.6.0.zip to C:\Temp (which should create the folder “C:\Temp\subversion-1.6.0″).

Make sure you have C:\Python26 in your path.

Creating the Visual Studio solution and compiling

Open a command prompt, go to C:\Temp\subversion-1.6.0, and run the following command:

1
gen-make.py -t vcproj --vsnet-version=2008 --with-swig=C:\Temp\swig --with-zlib=C:\temp\subversion-1.6.0\zlib --with-apr=C:\Temp\subversion-1.6.0\apr --with-apr-util=C:\Temp\subversion-1.6.0\apr-util --with-apr-iconv=C:\Temp\subversion-1.6.0\apr-iconv

The paths MUST be absolute like that, using “..\swig” will not work.

This will create the file subversion_vcnet.sln in the folder you’re in – we’ll leave this for a second to build some of the dependencies.

Open the file C:\Temp\subversion-1.6.0\apr\apr.dsw and select “Yes to all” to convert it to VS2008 format, set the build configuration to “Release”, and build.

Do the same thing with C:\Temp\subversion-1.6.0\apr-util\aprutil.dsw (this will ask if you want to use the .vcproj files you already converted in the previous step, answer “Yes” to this) – set to “Release” and build.

Open C:\Temp\subversion-1.6.0\subversion_vcnet.sln in Visual C++ (if you’re using the Express edition, you’ll get a few error messages about project folders not being supported, this won’t affect anything, so just “OK” them), set build configuration to Release (since Python 2.6 by default comes without debug DLLs), and build the sub-project “__SWIG_PYTHON__”.

This should compile with no errors (and few warnings).

Creating the libraries

Now you have all the files you need in C:\Temp\subversion-1.6.0\Release\subversion, so we’ll create the folder C:\Temp\svnpy to hold our “result”.

First, copy the folder C:\Temp\subversion-1.6.0\subversion\bindings\swig\python\svn to C:\Temp\svnpy\svn (this is the pure-python part of the library)

Then, create the folder C:\Temp\svnpy\libsvn and copy C:\Temp\subversion-1.6.0\subversion\bindings\swig\python\*.py here (these are the Swig interface files to the compiled library)

Do a Windows search for “*.dll” in C:\Temp\subversion-1.6.0\Release\subversion (since this will give you a single list of all DLLs in subfolders) and copy all of them to C:\Temp\svnpy\libsvn

Finally, rename all the DLLs starting with underscore (_core, _fs, _delta, _diff, _ra, _wc) from *.dll to *.pyd.

Copy svn and libsvn from C:\Temp\svnpy into C:\Python26\Lib\site-packages to install them.

Testing svn

From a Python command line, try the following:

1
from svn import core

If this doesn’t throw any errors, you have a working libsvn build!

Troubleshooting

The most common error is getting an exception that says: “_mod” is undefined.

To see the real error, try running the command:

1
from libsvn import _core

If the error says “DLL load failed: The specified procedure could not be found.”, check if you got all the .dlls copied over from the Release directory – they need to be from your build – even if this is svn 1.6.0, I couldn’t get the “official” 1.6.0 .dlls to work.

If the error is “please reinstall the application”, and there’s an entry in the Windows Event Log to the effect of

Resolve Partial Assembly failed for Microsoft.VC90.DebugCRT. The referenced assembly is not installed on your system.”

it means one or more of the libsvn*.dlls were compiled in debug mode (even if you set Release when building).

To fix this, open the VC++ 2008 solution again, Ctrl-select all the projects starting with “lib”, Properties, Linker->Debug, and turn off debugging. Re-compile the entire solution, and rebuild the modules as described under “Creating the libraries”

  • Share/Bookmark

Tags: , , , , , ,

5 Responses to “Compiling Subversion Python bindings on Windows”


  1. Making a Trac install work on Apache 2.2/Python 2.6/win32 - Saved for later reference
    on Mar 30th, 2009
    @ 12:52

    [...] Follow my previous guide to compile and install Python SVN bindings. [...]


  2. Chris
    on Aug 31st, 2009
    @ 19:24

    Interesting article, but I can’t get past the Visual Studio step.

    aprutil.dsw fails with 6 errors like:
    7>.\apr_dbd_mysql.c(29) : fatal error C1083: Cannot open include file: ‘mysql.h’: No such file or directory
    8>.\apr_dbd_freetds.c(39) : fatal error C1083: Cannot open include file: ‘sybdb.h’: No such file or directory

    subversion_vcnet.sln compiles without errors, but doesn’t create any files in C:\Temp\subversion-1.6.0\subversion\bindings\swig\python\. Only folders with names like python_repos, python_fs, etc.


  3. lejordet
    on Aug 31st, 2009
    @ 19:29

    Are you building all or just “__SWIG_PYTHON__”? I’ll try this again to update a newer version, so I’ll revise the steps if they’ve become incorrect in the mean time.


  4. lejordet
    on Sep 2nd, 2009
    @ 07:16

    I’ve been trying to repeat this for building SVN 1.6.5, and I’ve had some strange problems that didn’t occur the first time around – I’ll investigate if it’s due to changing the SVN version, or if there’s a problem with the procedure.

    Notable changes:
    - apr_* will build, but have 8-9 failed builds – the database modules won’t build unless you add in the proper libraries, which is outside the scope of this article, for now.
    - You might have to force VS2008 to recognize where your python.exe is found (Adding the path manually in options), otherwise some parts of the base library will build successfully (or so it seems), except there’s a line about not finding “python”, and nothing is really built.

    After a bit of work I got it to build, but the finished product, the .pyd/.py files, don’t work…


  5. Allard
    on Apr 1st, 2010
    @ 21:12

    This action:
    Do a Windows search for “*.dll” in C:\Temp\subversion-1.6.9\Release\subversion

    should be replaced by:
    Do a Windows search for “*.dll” in C:\Temp\subversion-1.6.9

    else you mis the APR dll’s and will get the python error:
    ImportError: DLL load failed: The specified module could not be found.

Leave a Reply

© 2009 Saved for later reference. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.