Tag Archives: pyinstaller failed to execute script

[Solved] Pyinstaller packaged exe error: “failed to execute script XXX”

Recently I wrote a small interface program with PyQt5, which needs to be packaged into exe for use on other windows. At the beginning, I used python 3.7 64-bit, packaged the exe with pyinstaller, and it ran normally on a 64-bit machine. But the target computer is 32-bit, so a 32-bit exe needs to be packaged, and then the problem occurs.

Package a 32-bit exe. Although there are online tutorials that use Anaconda to generate a python’s 32-bit environment, I tried it, but it was unsuccessful. Instead, I chose to uninstall the 64-bit python. It is better to install the 32-bit python directly and still use pyinstaller to package

Although there were a few warnings during packaging, it seemed that it went smoothly. I clicked on the exe and reported “failed to execute script XXX”. I changed multiple python versions, unloaded and unloaded, and turned over a lot of information, but I didn’t solve it, so I decided to self-reliance.

As we all know, you can use this command to package exe without console:

pyinstaller -w -F xxx.py 

But in this way, there is no way to see the error, so keep the console:

pyinstaller -F xxx.py 

After packaging, the program flashed by. I opened the video on my mobile phone and recorded it (60fps). The picture quality is stale but I still can’t miss the “unable to find QtCore.dll on PATH”:

The problem should be that the PyQt library is missing. If it is missing, just make it up~ Copy this dll directly to C:\Windows\System32, and then open the exe happily, the problem is solved~….. solve……

You need to add python’s PyQt5 library path to the environment variable PATH. This time, you can really run it. I am very happy (actually I have been tossing this step for a long time), but it is estimated that PyQt5 needs to be installed on the target computer, and then Adding environment variables, although a little troublesome, can be used.

That’s how things came to an end…

 

It didn’t come to an end. I was not reconciled. Why 64-bit runs well and 32-bit loses dll. Why does the command line run normally and exe loses something? And I went to the temporary directory of the exe and looked at it. In fact, Qt5Core.dll and other libraries are all lying in it, but why did it say that it could not be found, and then I tried

1. Forcibly repackage Qt5Core.dll in the exe, this can be achieved by editing the spec file, and changing the datas is OK, no!

2. Try to adjust the running path during runtime, or add a temporary path, so that the program can recognize the dlls originally in the same directory, but no similar tutorials were found (this requirement is originally weird?)

3. Changed to another one and tried it, built a virtual machine and tried it, to rule out system differences, it didn’t work.

4. I changed to a lower version of python and tried it, but it didn’t work

5. Try to replace the packaging software. It seems that most of them are pyinstaller, as well as py_win32, cx_Freeze, etc. py_win32 seems to need to rewrite the interface, and cx_Freeze runs according to the routine and has no effect at all.

It can be seen that the title is very close. In fact, it is enough to reduce the version of PyQt5. It seems that there is no need to reduce the version of pyinstaller (3.5) as in this blog post. After packaging, it can run normally without adding environment variables, and the exe size is also reduced. Half…

At the beginning, I used PyQt5.13.0 to package 32-bit error, and it was no problem if it was reduced to 5.9.2. By the way, remember that pip installs the specified version of the library:

pip install pyqt5==5.9.2

I like to write all kinds of dependent libraries in a cmd file. When I need to install the environment, double click and it will be done.

 

To summarize:

When Pyinstaller is packaging the PyQt5 program, if it prompts that the dll file is missing, you can try to reduce the version of PyQt5, such as the combination of pyinstaller3.5 + PyQt5.9.2 (@Windows 7 x64 SP1 + python 3.7.4 x32)