事实上,我无法重现你的错误。但我很难冻结使用的应用程序pygame
这也应该可以解决你的问题。
有时更好的方法是手动包含模块。首先,您需要排除您的模块exclude-module https://pyinstaller.readthedocs.io/en/v3.5/usage.html#what-to-bundle-where-to-search并将模块手动提供给最终的可执行文件Tree https://pythonhosted.org/PyInstaller/advanced-topics.html#the-toc-and-tree-classes班级。同样使用此方法,一些 Python 库会丢失,需要通过以下方式添加hidden-import https://pythonhosted.org/PyInstaller/when-things-go-wrong.html#listing-hidden-imports or Tree https://pythonhosted.org/PyInstaller/advanced-topics.html#the-toc-and-tree-classes。例如,我在这里添加了xml
as Tree
and queue
as hidden-import
.
import`. Use below spec file:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['script.py'],
pathex=['C:\\Users\\Rahimi\\Desktop\\test'],
binaries=[],
datas=[],
hiddenimports=['queue'],
hookspath=[],
runtime_hooks=[],
excludes=['pygame'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
a.datas += Tree("<python_path>/Lib/site-packages/pygame/", prefix= "pygame")
a.datas += Tree("<python_path>/lib/xml/", prefix= "xml")
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='script',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
runtime_tmpdir=None,
console=True )
请记住根据您当前的环境编辑路径。最后,使用以下命令生成可执行文件:
pyinstaller script.spec