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

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.

Leave a Comment