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?

2
  • 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)? Commented May 14, 2012 at 11:48
  • 1
    You caught me, I copy and pasted the error from running import svn.core at the interactive prompt Commented May 14, 2012 at 13:06

2 Answers 2

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).

Sign up to request clarification or add additional context in comments.

4 Comments

Alas, my OS is Windows right now, it doesn't have a package manager. I'm happy to use pysvn if you can link me to the documentation.
@MattHickford Updated with a link to pysvn.
That library pysvn was great and did what I wanted
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.