6

In Subversion's documentation there's an example of using Subversion from Python

#!/usr/bin/python
import svn.fs, svn.core, svn.repos

def crawl_filesystem_dir(root, directory):
    """Recursively crawl DIRECTORY under ROOT in the filesystem, and return a list of all the paths at or below DIRECTORY."""

    # Get the directory entries for DIRECTORY.
    entries = svn.fs.svn_fs_dir_entries(root, directory)

When I run this code I get an import error:

$ python crawl.py
Traceback (most recent call last):
  File "crawl.py", line 7, in <module>
    import svn.fs, svn.core, svn.repos
ImportError: No module named svn.fs

This means I'm missing the library svn. I tried to install the package, but the Python package manager can't find it.

$ pip install svn
Downloading/unpacking svn
  Could not find any downloads that satisfy the requirement svn
No distributions at all found for svn

So, how do I install this library?

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
  • 1
    Isn't it a little odd that it complains about `svn.core` but not about `svn.fs` (the latter comes first on the import list)? – NPE May 14 '12 at 11:48
  • 1
    You caught me, I copy and pasted the error from running `import svn.core` at the interactive prompt – Colonel Panic May 14 '12 at 13:06

2 Answers2

9

The library referred to by this documentation is the SWIG-based wrappers which build and ship with Subversion itself. Thus -- if your operating system's package is subversion, look for a subversion-python package to ship alongside it. If you're building subversion from source, you'll want to use the --with-python configure option for the bindings to be built alongside.

An alternative (with a quite different API) is the 3rd-party wrapper pysvn. These are better-documented and are easier to use, but are also less efficient in terms of runtime performance (they don't implement all the connection reuse capabilities and such of the underdocumented "official" bindings).

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
2

You need to install subversion-python in order to be able to import the classes.

In my case (Fedora)

sudo yum install subversion-python

Apt-get should have more or less the same

Rudi Strydom
  • 4,417
  • 5
  • 21
  • 30