2013-11-28 131 views
0

我有下面的代碼並運行到,即使shlex定義以下錯誤..NameError:全局名稱 'shlex' 沒有定義

import shlex 
import sys 
import subprocess 
def main(): 

    branch_name = sys.argv[1] 
    print "branch_name" 
    print branch_name 
    print "start repo..." 
    RepoInitCmd = 'repo init -u git://git.quicinc.com/platform/manifest.git -b ' + branch_name 
    proc = subprocess.Popen(shlex.split(RepoInitCmd), stderr=subprocess.PIPE) 
    out, error = proc.communicate() 
    print "Done repo..." 

if __name__ == '__main__': 
    main() 

錯誤: -

Traceback (most recent call last): 
    File "repoinit.py", line 15, in <module> 
    if __name__ == '__main__': 
    File "repoinit.py", line 10, in main 
    RepoInitCmd = 'repo init -u git://git.quicinc.com/platform/manifest.git -b ' + branch_name 
NameError: global name 'shlex' is not defined 
+0

'pip install shlex' – Farhadix

+3

有點奇怪。您的錯誤消息與回溯中顯示的代碼行不匹配。 – DSM

+1

你可以刪除任何'.pyc'文件並重試嗎? –

回答

2

如果shlex名沒有定義,這意味着你沒有在代碼中導入模塊。這意味着真實的代碼與您在問題中寫下的內容不符。如果沒有安裝shlex,它將在行import shlex上失敗。

相關問題