2012-02-20 31 views
0

我想運行現有的python代碼,並且遇到問題。如何在windows xp上正確使用subproces.Popen? - 在訪問npm時顯示windowserror 2

該程序需要安裝npm程序,並安裝在我的電腦的C:\ Program Files \ nodejs \ npm中。當我運行下面的代碼時,作爲整個程序的一部分,它會引發錯誤。

def popen_results(args): 
    proc = subprocess.Popen(args, stdout=subprocess.PIPE) 
    return proc.communicate()[0] 

def installed(): 
    """docstring for npm_installed""" 
    return popen_results(["which", "npm"]).strip() 

這是錯誤的thrown--

Checking for node and dependencies 
Traceback (most recent call last): 
    File "deploy\deploy.py", line 344, in <module> 
    main() 
    File "deploy\deploy.py", line 287, in main 
    if not check_deps(): 
    File "deploy\deploy.py", line 201, in check_deps 
    return npm.check_dependencies() 
    File "C:\Documents and Settings\Sunil\workspace\khan\src\deploy\npm.py", line 
38, in check_dependencies 
    if not installed(): 
    File "C:\Documents and Settings\Sunil\workspace\khan\src\deploy\npm.py", line 
13, in installed 
    return popen_results(["which", "npm"]).strip() 
    File "C:\Documents and Settings\Sunil\workspace\khan\src\deploy\npm.py", line 
8, in popen_results 
    proc = subprocess.Popen(args, stdout=subprocess.PIPE) 
    File "C:\python25\lib\subprocess.py", line 594, in __init__ 
    errread, errwrite) 
    File "C:\python25\lib\subprocess.py", line 822, in _execute_child 
    startupinfo) 
WindowsError: [Error 2] The system cannot find the file specified 
+0

在我看來就像它找不到'which'命令。 – martineau 2012-02-20 18:41:48

回答

0

我同意蒂諾完整的堆棧,它是無法找到它。該腳本可能是在假定它將在unix環境中運行的情況下編寫的,該環境很可能具有可用的「which」命令以及默認的PATH。因爲它看起來像你在Windows上運行這個,我不認爲它會起作用。

它看起來像有一些替代品,其在Windows不過,這裏討論:Is there an equivalent to which on Windows?