PyInstaller:单文件可执行文件不运行 [英] PyInstaller: Single-file executable doesn't run

查看:64
本文介绍了PyInstaller:单文件可执行文件不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pyinstaller 从 Python 应用程序为 Windows 创建单文件可执行文件.

我从 (用于 eXectutables 的终极打包程序)引起的,该工具旨在减少可执行文件的大小.如果 PyInstaller 在系统中找到 UPX,它默认使用 UPX.由于我仍然无法理解的原因,UPX 打包的可执行文件需要很长时间才能自解压和运行.

因此,只需运行带有 --noupx 选项的命令即可解决问题.

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

有关详细信息,请查看 GitHub 问题.

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.

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.

解决方案

I managed to solve this issue.

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

Actually, 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 in the system. For reasons that I still can't grasp, the UPX-packed executable took an extremely long time to self-extract and run.

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

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

For more information, check out the GitHub issue.

这篇关于PyInstaller:单文件可执行文件不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆