CreateProcess error = 2,无法运行程序" python"在Ant上

时间:2017-04-04 13:28:07

标签: java python ant

当我通过Ant运行我的xml代码时出现C:\Users\Sony\Desktop\Project\Workspace\testpython\verify_fam_extended.xml:52: Execute failed: java.io.IOException: Cannot run program "python" (in directory "C:\Users\Sony\Desktop\Project\Workspace\testpython\backend\generated"): CreateProcess error=2, The system cannot find the file specified错误。

<exec dir="backend/generated" executable="python">
    <arg line="toplevel.py"/>
    <env key="PYTHONPATH" value="${dsltrans.install.path}:./backend/generated"/> 
</exec>

1 个答案:

答案 0 :(得分:0)

编辑 python.exe必须位于可执行路径变量PATH中定义的目录中。

以下工作示例假定存在C:\Python33\python.exe

<project name="demo" default="main" basedir=".">
  <property environment="env" />
  <echo>PATH is set as: ${env.PATH}</echo>

  <target name="main">
    <exec dir="backend/generated" executable="python">
      <arg line="--version"/>
    </exec>        
  </target>                                
</project>

在命令会话中执行

set PATH=C:\Python33;%PATH%
ant 

输出

Buildfile: X:\temp\build.xml
     [echo] PATH is set as: C:\Python33;...
...
main:
     [exec] Python 3.3.0

修改刚检查过。可执行文件可以是executable="python"executable="python.exe"。所以@cdarke是正确的问题是python.exe不在PATH