首页 > 解决方案 > java.io.IOException:无法运行程序“python”(在目录“D:\Doc\module\subject”中):CreateProcess 错误=2,

问题描述

在此处输入图像描述我正在尝试执行一个简单的 python cmd 命令,例如 C:\Users> python swaggerpythonfile.py < Documents/inputfile/swagger.yaml > Documents/outputfile/doc.htmlmaven 项目中的 python 脚本。此命令 simpy 需要一个 .yaml 文件并通过执行 python 文件 swaggerpythonfile.py 将其转换为 html 文件,并且可以在我的 cmd 中正常工作。但是,我需要将它作为一个 python 脚本放在一个 maven 项目中,所以我尝试按照 exec-maven-plugin 文档链接!. 但我收到一个错误。

[错误] 命令执行失败。java.io.IOException: Cannot run program "python" (in directory "D:\DocAuth\modules\subjectstore"): CreateProcess error=2, 系统找不到指定的文件

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
            <execution>
                <configuration>
                    <executable>python</executable>
                    <workingDirectory>${basedir}</workingDirectory>
                    <arguments>
                        <argument>swagger-yaml-to-html.py</argument>  
                        <argument>generated/inputfile/swagger-ui/swagger.yaml</argument>
                      <argument>target/outputfile/doc.html</argument>
                    </arguments>

                </configuration>
                <id>python_build</id>
                <phase>generate-resources</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

[错误] 无法在项目上执行目标 org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (python_build)

错误输出图像

标签: pythonmaven-pluginexec-maven-plugin

解决方案


我在您的评论中看到您通过包含 Python 可执行文件的完整路径解决了这个问题,但是您可以将 Python 添加到您的 PATH 中(我建议这样做,因为这可能不是您要使用 Python 的唯一一次)。

您可以使用以下命令将 Python 文件夹添加到 PATH:

setx path "%path%;<full-path-to-Python-base-folder>"

或按照此处的说明进行操作:https ://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

注意:我发现在 Eclipse 中开发时,我必须重新启动它才能获取 PATH 中的更改。通常,更改环境变量时可能需要重新启动应用程序。


推荐阅读