Fix PyInstaller Failed to execute script Error – Python Tutorial

By | April 19, 2021

When we use pyinstaller to pack python script to exe application, we may get Failed to execute script Error. In this tutorial, we will introduce you how to fix.

Failed to execute script error looks like:

pyinstaller failed to execute script

How to fix this error?

The simplest way is we pack python script to exe application with console based. Here is an example:

pyinstaller --noconfirm --onefile --console  "E:/workspace-nlp/PythonScript/"

Then, we will run main.exe with command prompt in windows 10.

run python exe from cmd

As to us, we can find the reason why main.exe reports Failed to execute script error.

pyinstaller ModuleNotFoundError

Install python socks library, you can read this tutorial:

Fix ModuleNotFoundError: No module named ‘socks’ Error – Python Tutorial

Finally, we will pack our python script again, we find this error is fixed.