2012-05-29 149 views
0

我正在使用GitPython将远程存储库提取到我的机器上。以下代码适用于我的Ubuntu 12.04,但在我的amazon ec2上,在Ubuntu 11.10服务器上,我得到OSError:[Errno 2]没有这样的文件或目录错误。OSError:[Errno 2] GitPython上没有这样的文件或目录

repo = git.Repo.init(fs_path) 
    origin = repo.create_remote('origin',repo_url) 
    origin.fetch() 
    origin.pull(origin.refs[0].remote_head) 

当我在脚本中运行该块时,我没有收到任何错误消息。但是当我在交互式shell上尝试这些步骤时,我得到这个堆栈跟踪:

>>> import git 
>>> repo = git.Repo.init("/var/wwww/dir/subdir/tmp/12") 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/repo/base.py", line 656, in init 
    output = git.init(**kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/cmd.py", line 227, in <lambda> 
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/cmd.py", line 456, in _call_process 
    return self.execute(call, **_kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/GitPython-0.3.2.RC1-py2.7.egg/git/cmd.py", line 335, in execute 
    **subprocess_kwargs 
    File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ 
    errread, errwrite) 
    File "/usr/lib/python2.7/subprocess.py", line 1239, in _execute_child 
    raise child_exception 
OSError: [Errno 2] No such file or directory 
>>> 

但是我在本地机器上没有这样的问题。不知道发生了什么问题。任何帮助将不胜感激!

+0

路径存在,python可以访问它 – masnun

回答

2

错误来自subprocess模块。这表明git未安装在EC2实例上,或者位于PATH环境变量中的某个位置。

请注意,GitPython取决于git命令行工具。如果你想要一个本地Python模块来与Git仓库进行交互,请看dulwich

+0

我刚刚发现我自己并来到这里回答这个问题。是的,的确,我没有安装git,导致了错误。感谢你的及时回复。 我只希望Gitpython发出更有意义的错误消息/异常。如果一个库依赖于一个外部工具,库应该做的第一件事就是检查是否安装了依赖关系。有这个艰难的一个小时。 再次感谢! – masnun

+0

我很高兴它解决了。 – larsks

相关问题