2012-05-14 126 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 

易於得到應有或多或少相同