close

[Solved] Windows- Pyinstaller Error “failed to execute script ” When App Clicked

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Windows- Pyinstaller Error “failed to execute script ” When App Clicked in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Windows- Pyinstaller Error “failed to execute script ” When App Clicked Error Occurs?

Today I get the following error Windows- Pyinstaller Error “failed to execute script ” When App Clicked in python.

How To Solve Windows- Pyinstaller Error “failed to execute script ” When App Clicked Error ?

  1. How To Solve Windows- Pyinstaller Error “failed to execute script ” When App Clicked Error ?

    To Solve Windows- Pyinstaller Error “failed to execute script ” When App Clicked Error So The Simple answer is to place all the media files or folders which were used by code in the directory where exe file is there.

  2. Windows- Pyinstaller Error “failed to execute script ” When App Clicked

    To Solve Windows- Pyinstaller Error “failed to execute script ” When App Clicked Error So The Simple answer is to place all the media files or folders which were used by code in the directory where exe file is there.

Solution 1

Well I guess I have found the solution for my own question, here is how I did it:

Eventhough I was being able to successfully run the program using normal python command as well as successfully run pyinstaller and be able to execute the app “new_app.exe” using the command line mentioned in the question which in both cases display the GUI with no problem at all. However, only when I click the application it won’t allow to display the GUI and no error is generated.

So, What I did is I added an extra parameter –debug in the pyinstaller command and removing the –windowed parameter so that I can see what is actually happening when the app is clicked and I found out there was an error which made a lot of sense when I trace it, it basically complained that “some_image.jpg” no such file or directory.

The reason why it complains and didn’t complain when I ran the script from the first place or even using the command line “./” is because the file image existed in the same path as the script located but when pyinstaller created “dist” directory which has the app product it makes a perfect sense that the image file is not there and so I basically moved it to that dist directory where the clickable app is there!

So The Simple answer is to place all the media files or folders which were used by code in the directory where exe file is there.

Second method is to add “–add-data <path to file/folder>”(this can be used multiple times to add different files) option in pyinstaller command this will automatically put the given file or folder into the exe folder.

Solution 2

In my case i have a main.py that have dependencies with other files. After I build that app with py installer using this command:

pyinstaller --onefile --windowed main.py

I got the main.exe inside dist folder. I double clicked on this file, and I raised the error mentioned above. To fix this, I just copy the main.exe from dist directory to previous directory, which is the root directory of my main.py and the dependency files, and I got no error after run the main.exe.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read