PyInstaller: single-file executable does not start

I am trying to create a single-file executable for Windows from a Python application using pyinstaller .

I downloaded the experimental Python 3 pyinstaller from here (scroll down and you will find the download link, py3.zip file). And I installed it using python setup.py install . UPDATE: I also tried it with the Python 2 version and ran into the same problem.

Then I created a test python script called test.py with the following contents:

 print('Hello, World!') 

Then I ran the following command to create a single-file executable:

 pyinstaller --onefile test.py 

The command completed successfully, and I confirmed that the dist/test.exe file was created. However, when I try to start it, all I get is an empty console window. Nothing appears and the program never ends. It just hangs there forever until I close it.

I get an empty console window.

Calling pyinstaller test.py (without the --onefile option) works fine. So what is the problem?

Please note that using py2exe or cx_freeze not an option. It must be a pyinstaller .

UPDATE: I just tested it under Python 2 (using the regular version of PyInstaller), and I ran into the same problem. So this is not just a Python 3 issue.

+6
source share
1 answer

I managed to solve this problem.

I found out that the program really started. However, he hanged himself for a long time (for example, 5 minutes!) Before displaying the message Hello, World! .

In fact, the problem was caused by UPX (Ultimate Packer for eXectutables), a tool whose purpose is to reduce the size of executable files, PyInstaller uses UPX by default if it finds it on the system. For reasons that I still cannot understand, the UPX-packed executable took a very long time to self-extract and run.

So, just running the command with the --noupx option --noupx problem.

 pyinstaller --debug --onefile --noupx test.py 

Check out the GitHub issue for more information.

+11
source

Source: https://habr.com/ru/post/982056/


All Articles