Python Subversion wrapper library

馋奶兔 提交于 2019-12-04 22:15:19

问题


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?


回答1:


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




回答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



来源:https://stackoverflow.com/questions/10582469/python-subversion-wrapper-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!