我正在编写 python 程序来使用 git 存储库,它可以在 win7 上正常工作,但我还需要这个程序在 win xp 上工作(win xp 支持 python 3.4,pygit2 0.28 不能在 win xp 上工作(dll 导入错误)所以我安装了 pygit2 0.25.0) 我正在使用 pyinstaller 来构建 .exe
p = pygit2.Repository(repository_path)
生成异常(在 Windows XP 上):
无法解析路径“C:\TestRepository.git”:参数无效
def get_repo():
repository_path = "C:\\TestRepository\\.git"
try:
p = pygit2.Repository(repository_path)
except Exception as e:
print(str(e) + " (exception)") # print to console
return None
return p
我尝试了什么:
repository_path = Path("C:\\TestRepository\\.git").resolve()
返回异常:必须是 str,而不是 windows 路径
repository_path = "C:/TestRepository/.git"
repository_path = b"C:\\TestRepository\\.git"
repository_path = r"C:\TestRepository\.git"
repository_path = "C:\\TestRepository\\.git".encode("utf-8")
返回异常:无法解析路径“C:\TestRepository.git”:无效参数
我希望函数 get_repo 返回 Repository