我正在尝试捆绑 cefpython1使用 pyinstaller 将应用程序转换为单个 exe。 我有一个工作规范文件,它为 cefpython1 示例创建了一个发行版,cefsimple:
# -*- mode: python -*-
def get_cefpython_path():
import cefpython1 as cefpython
path = os.path.dirname(cefpython.__file__)
return "%s%s" % (path, os.sep)
cefp = get_cefpython_path()
a = Analysis(['cefsimple.py'],
hiddenimports=["json.decoder", "json.scanner", "json.encoder"])
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='cefsimple.exe',
debug=False,
strip=None,
upx=False,
console=False )
coll = COLLECT(exe,
a.binaries + [('icudt.dll', '%s/icudt.dll' % cefp, 'BINARY')],
a.zipfiles,
a.datas + [('locales/en-US.pak', '%s/locales/en-US.pak' % cefp, 'DATA'), ('cefsimple.html', 'cefsimple.html', 'DATA'), ('icon.ico', 'icon.ico', 'DATA')],
strip=None,
upx=False,
name='cefsimple')
可以找到项目文件on my Google Drive .不要关心 setup.py,它包含一个 py2exe 构建,我在 pyinstaller 旁边玩过。你需要 Python 2.7、Win32gui、cefpython1,当然还有 pyinstaller 包来运行它,我只用 Win32 版本测试过它!如果有任何更改,我什至尝试安装开发 pyinstaller。
如果我尝试使用 --onefile 属性执行 pyinstaller 似乎没有任何变化,pyinstaller 只是在 dist 下创建分发目录。我使用的命令是:pyinstaller --onefile cefsimple.spec
使用简单的 Hello World python 文件测试了 --onefile,它确实可以正常工作。是什么导致 pyinstaller 不创建单个 exe? build log没有显示任何有趣的东西,但在 warning file 中有些东西我不明白.例如。它说没有名为 cefpython1.cefpython 的模块,但正确的 pyd 被复制到 dist 目录,应用程序仍然可以正常工作。
这是在 dist/下创建的文件列表:cefsimple.lst也许这有助于发现问题。
最佳答案
The command I'm using is:
pyinstaller --onefile cefsimple.spec
Tested --onefile with a simple Hello World python file and it does work by that. What's causing pyinstaller to not creating a single exe?
当您键入 pyinstaller --onefile cefsimple.spec
时,选项 --onefile 会被忽略,因为 .spec 已经定义了您是获取目录还是独立文件.具有 COLLECT 函数的 .spec 文件将创建一个完整的 dist
目录。
我建议通过键入 pyi-makespec --onefile cefsimple.py
重新制作一个新的 .spec 文件并添加您的各种修改(数据、二进制文件、hiddenimports...),然后尝试不带选项的pyinstaller cefsimple.spec
。这适用于 pyinstaller 3.3.1。
关于python - pyinstaller 不使用 --onefile 捆绑 pyd 和 dll 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25472972/