Windows- Pyinstaller Error "Failed to Execute Script " When App Clicked

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.

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

I am guessing you only have one script, so if you use:

Pyinstaller --onefile yourScript.py

Replacing yourScript.py with the name of your python file in the CMD/Terminal, you shouldn't have any problems.

If you are missing a binary, this should help. For example pyinstaller was missing the currency converter module, so I found and it, got the zip file and then ran this in CMD:

Pyinstaller --add-binary "C:\Users\myName\Downloads\eurofxref-hist.zip";currency_converter --onefile myScript.py

Where myScript.py is my Python script, and the link is to the folder with the binary zip file.

Failed to execute script pyinstaller

This may be due to pyinstaller not being able to properly find your dependencies and skipping some packages.

To fix any error like ModuleNotFoundError: No module named 'PIL' just add it as a hidden import:

pyinstaller --onefile --hidden-import=PIL -w script.py

For the second error this is a known issue with pyinstaller and pynput.
Find here some explanation.

The TLDR of it seems to be that you need to add --hidden-import=pynput.mouse._win32 --hidden-import=pynput.keyboard._win32 --hidden-import=pynput._util._win32 and any other sub-packages that give you errors.

Pyinstaller - failed to execute script: why?

I found the answer to my problem. It turns out, it had nothing to do with images. It had to do with the font. Normally, in PyCharm (maybe I'm mistaken) freesansbold.ttf is a default font. However, when PyInstaller packages the files, PyInstaller doesn't have the font downloaded by default, so it gives an error. All I had to do was scour the internet for the font, downloaded it, and it worked.

So yeah, pretty funny mistake.



Related Topics



Leave a reply



Submit