Saved for later reference

online repository of stuff I had to google for hours to figure out – and random snippets of code

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

Tags: , , , , , ,

© 2009 Saved for later reference. All Rights Reserved.

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