2012-02-20 58 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?

相关问题