2012-05-14 63 views
6

在Subversion的documentation有使用Subversion从Python的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) 

当我运行这段代码,我得到一个导入错误的例子:

$ 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 

这意味着我失踪了库svn。我试图安装这个软件包,但是Python软件包管理器找不到它。

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

那么,我该如何安装这个库?

+1

是不是有点古怪,它抱怨'svn.core'但不是' svn.fs'(后者首先在导入列表中)? – NPE

+1

你抓到我了,我复制并粘贴了在交互式提示符下运行'import svn.core'的错误 –

回答

9

本文档引用的库是基于SWIG构建并随Subversion一起发布的包装器。因此 - 如果您的操作系统的软件包是subversion,请查找subversion-python软件包以便与其一起发货。如果你从源代码构建颠覆,你会想要使用--with-python配置选项来构建绑定。

替代方案(具有完全不同的API)是the 3rd-party wrapper pysvn。它们有更好的文档记录并且更易于使用,但在运行时性能方面效率较低(它们不实现所有连接重用功能以及未被记录的“官方”绑定)。

+0

唉,我的操作系统现在是Windows,它没有包管理器。如果你能将我链接到文档,我很乐意使用'pysvn'。 –

+0

@MattHickford更新了链接到pysvn。 –

+1

谢谢发现难以捉摸的文件http://pysvn.tigris.org/docs/pysvn_prog_guide.html http://pysvn.tigris.org/docs/pysvn_prog_ref.html –

2

您需要安装subversion-python才能导入类。

在我的情况(Fedora的)

sudo yum install subversion-python 

易于得到应有或多或少相同