一个Python程序,我使用pyInstaller编译后,大小超过了400MB。该程序的GUI基于htmlPY,它是“PySide's QtWebKit库”的封装。程序的巨大大小部分归因于它使用了numpy、scipy和nltk,并且还有图形库。
为了最小化程序的大小,我安装了UPX。这将程序的大小减小到略大于100MB,这是可以接受的。
第一个问题是pyInstaller没有检测到htmlPy,并且没有将其包含在编译后的程序中。这可以通过将htmlPy模块从我的Python安装中复制到pyInstaller创建的“dist”目录中来解决。这样做后,没有使用UPX编译的版本的程序工作正常。
在将htmlPy添加到“dist”目录后,运行可执行文件时,在创建GUI时程序崩溃。我不确定这是否是由于UPX和QT之间的问题交互作用,还是由于UPX、QT和htmlPy之间的问题交互作用。Windows的“问题签名”如下:
任何想法关于这里发生了什么,以及如何修复它?
编辑:
这是我的.spec文件的内容:
程序在到达第三步之前崩溃。
为了最小化程序的大小,我安装了UPX。这将程序的大小减小到略大于100MB,这是可以接受的。
第一个问题是pyInstaller没有检测到htmlPy,并且没有将其包含在编译后的程序中。这可以通过将htmlPy模块从我的Python安装中复制到pyInstaller创建的“dist”目录中来解决。这样做后,没有使用UPX编译的版本的程序工作正常。
在将htmlPy添加到“dist”目录后,运行可执行文件时,在创建GUI时程序崩溃。我不确定这是否是由于UPX和QT之间的问题交互作用,还是由于UPX、QT和htmlPy之间的问题交互作用。Windows的“问题签名”如下:
Problem signature:
Problem Event Name: APPCRASH
Application Name: main.exe
Application Version: 0.0.0.0
Application Timestamp: 00000000
Fault Module Name: QtCore4.dll
Fault Module Version: 4.8.7.0
Fault Module Timestamp: 561e435a
Exception Code: c0000005
Exception Offset: 000000000010883a
任何想法关于这里发生了什么,以及如何修复它?
编辑:
这是我的.spec文件的内容:
# -*- mode: python -*-
block_cipher = None
added_files = [
( 'htmlPy/binder.js', 'htmlPy' ),
( 'templates/*', 'templates' ),
]
a = Analysis(['main.py'],
pathex=['C:\\..\\My_App'],
binaries=None,
datas=added_files,
hiddenimports=[],
hookspath=[],
runtime_hooks=['rthook_pyqt4.py'],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='My_App',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='My_App')
这是rthook_pyqt4.py的内容:
import sip
sip.setapi(u'QDate', 2)
sip.setapi(u'QDateTime', 2)
sip.setapi(u'QString', 2)
sip.setapi(u'QTextStream', 2)
sip.setapi(u'QTime', 2)
sip.setapi(u'QUrl', 2)
sip.setapi(u'QVariant', 2)
编辑2:
这是一些初始化代码(标准htmlPy表现):
app.static_path = path.join(BASE_DIR, "static/")
print "Step 1"
app.template_path = path.join(BASE_DIR, "templates/")
print "Step 2"
app.template = ("index.html", {"username": "htmlPy_user"})
print "Step 3"
...
程序在到达第三步之前崩溃。
.spec
文件。恐怕在这种情况下,你需要一个来添加binder.js
作为数据文件。我将在下面添加详细的答案。 - Repiklis('C:\\Python35-32\\Lib\\site-packages\\....\\Qt4Core.dll', '.')
。 - sytech