2012-05-29 145 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

相關問題