Solve – PyInstaller Failed to execute script Error in Python

Solve – PyInstaller Failed to execute script Error in Python is an error which happens with pyinstaller for different reasons.

In this Blog Post, I am going to try and solve the error while I try to explain why the error is actually happening, we will also introduce some solutions that have worked for other developers and see if those solutions can solve the problem for you.

Explaining the Error : PyInstaller Failed to execute script Error in Python

This is one of those errors in Python that are hard to reproduce, to be more precise it is easy to reproduce but it is hard to reproduce the cause of the problem.

Which means that there are a lot of scenarios that may cause the error and there are a lot of possible fixes.

The error you are getting should be very similar to the error message bellow.

                                                                       #
"failed to execute script new-app" 
                                                                       #

In the sections bellow we will explain the root of the error more and propose some possible fixes.

Solution 1 : Move media files to the .exe directory

First of all this is error is confusing but it is easy to fix. I would say with confidence that this solution will fix the error for 90 percent of people.

Read my explanation carefully, because by understanding the error you will understand the fix.

This error usually happens when you have a missing image or media file, but in most cases you wont see that in the error message.

The solution is to move all the images and the media files to the folder where the .exe generated by Pyinstaller exists.

Now, run your code again and the error should be gone for good.

Solution 2 : Move the .exe to the initial directory

The second solution will serve the same purpose as the first solution, the error is still the same but the fix you are going to try is different.

In the error above we said that you should move the media files to the directory where the generated .exe resides.

You can do the opposite of that, by just copying the .exe files to the previous directory.

This way, all the media files will exist in the same directory where the .exe file lives.

The error should be gone on the next run.

Solution 3 : use pure Python

For a minority of people, this error happens with anaconda.

When you use PyInstaller, it packs the script with Python and not anaconda.

As a result, modules will not exist in python’s library folder and the error will occur. The solution in this case is to drop anaconda and use pure Python only since that is what PyInstaller understands.

This error could be confusing at first. But once you understand why it is happening, it is easy to solve.

Summing-up

Guys, this has been my best attempt at helping you understand and solve this issue. I hope you found a solution which suits your needs.

Consider helping the blog if you can by donating to our Kofi account. Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/