在 Subversion 的 documentation 中有一个从 Python 使用 Subversion 的例子
#!/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
那么,我该如何安装这个库呢?
最佳答案
本文档引用的库是基于 SWIG 的包装器,它与 Subversion 本身一起构建和发布。因此——如果您的操作系统的包是 subversion
,请寻找一个 subversion-python
包与它一起发布。如果您从源代码构建颠覆,您需要使用 --with-python
配置选项来同时构建绑定(bind)。
另一种选择(具有完全不同的 API)是 the 3rd-party wrapper pysvn
.它们有更好的文档记录并且更易于使用,但在运行时性能方面效率也较低(它们没有实现所有连接重用功能以及文档不足的“官方”绑定(bind))。
关于Python Subversion 包装器库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10582469/