21

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

I downloaded the experimental Python 3 branch of pyinstaller from here (the file was python3.zip, but the link is now dead). And I installed it using python setup.py install.

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

print('Hello, World!') 

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

pyinstaller --onefile test.py 

The command succeeded, and I verified that the file dist/test.exe had been generated. However, when I try to run it, all I get is an empty console window. Nothing ever appears, and the program never terminates. It just hangs there forever, until I force close it.

I get an empty console window.

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

Notice that using py2exe or cx_freeze is not an option. It has to be pyinstaller.

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

11
  • where did you install from? Commented Feb 5, 2015 at 16:50
  • @PadraicCunningham I downloaded it from the link I provided. If you go here: github.com/pyinstaller/pyinstaller/wiki and scroll down, there is a download link for the Python 3 version. Commented Feb 5, 2015 at 16:55
  • the link seems to bring me nowhere? I tried, admittedly using linux installing using pip3 install https://github.com/pyinstaller/pyinstaller/archive/python3.zip and it works fine so might be worth giving it a shot unless that is actually the link you were trying to post. Commented Feb 5, 2015 at 16:57
  • did you use python or python3 to setup.py install? Commented Feb 5, 2015 at 16:59
  • so python3 setup.py install? Commented Feb 5, 2015 at 17:00

1 Answer 1

29

I managed to solve the issue.

I found out that the program did, in fact, run. However, it hung for a long time (like 5 minutes!) before displaying the Hello, World! message.

The problem was caused by UPX (Ultimate Packer for eXectutables), a tool that aims to reduce the size of executable files. PyInstaller uses UPX by default if it finds it on the system. For reasons that I still can't grasp, the UPX-packed executable took an extremely long time to self-extract and run.

Thus, simply running the command with the --noupx option fixed the problem.

pyinstaller --onefile --noupx test.py 

As a sidenote, adding the --debug option to the pyinstaller command can usually help identify problems such as this one.

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting - UPX ran quite fast, whenever I used it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.