enter image description here我正在尝试执行一个简单的python cmd命令,例如
C:\Users> python swaggerpythonfile.py < Documents/inputfile/swagger.yaml > Documents/outputfile/doc.html
作为Maven项目中的python脚本。此命令simpy需要一个.yaml文件,并通过执行python文件swaggerpythonfile.py将其转换为html文件,并且可以从我的cmd正常工作。但是,我需要将其作为python脚本放入Maven项目中,因此我尝试遵循exec-maven-plugin文档a link! 。但是我遇到一个错误。
[错误]命令执行失败。 java.io.IOException:无法运行程序“ python”(在目录“ 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)
答案 0 :(得分:1)
我在您的评论中看到,您通过包括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中进行更改。通常,更改环境变量时可能必须重新启动应用程序。