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
'pip install shlex' – Farhadix
有點奇怪。您的錯誤消息與回溯中顯示的代碼行不匹配。 – DSM
你可以刪除任何'.pyc'文件並重試嗎? –