jks
jks

Reputation: 137

java.io.IOException: Cannot run program "python" (in directory "D:\Doc\module\subject"): CreateProcess error=2,

enter image description hereI am trying to execute a simple python cmd command like C:\Users> python swaggerpythonfile.py < Documents/inputfile/swagger.yaml > Documents/outputfile/doc.html as a python script in a maven project. This command simpy takes a .yaml file and convert it to html file by executing python file swaggerpythonfile.py and works fine from my cmd. However, I need to put it as a a python script in a maven project so i tried to follow the exec-maven-plugin documentation a link! . But i am getting an error.

[ERROR] Command execution failed. java.io.IOException: Cannot run program "python" (in directory "D:\DocAuth\modules\subjectstore"): CreateProcess error=2, The system cannot find the file specified

    <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>

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (python_build) on project

ERROR OUTPUT IMAGE

Upvotes: 1

Views: 6405

Answers (1)

Cal
Cal

Reputation: 41

I see in your comment that you solved this by including the full path to the Python executable, but instead you can add Python to your PATH (which I recommend because this is probably not the only time you are going to use Python).

You can add the Python folder to your PATH with this command:

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

Or follow the instructions here: https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

Note: I found when developing in Eclipse that I had to restart it for it to pick up changes in the PATH. In general, you will probably have to restart applications when changing environment variables.

Upvotes: 3

Related Questions