我正在尝试使用 PyInstaller 为 Asciimatics 编译一个演示脚本,希望最终能够为我正在开发的基于文本的游戏创建一个简单的 GUI,但它返回以下错误:
C:\Users\X\Documents\Python Scripts\asciimatics samples\dist\test>test.exe
Traceback (most recent call last):
File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources__init__.py", line 443, in get_provider
KeyError: 'pyfiglet.fonts'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 22, in <module>
File "site-packages\asciimatics\screen.py", line 859, in wrapper
File "<string>", line 12, in demo
File "site-packages\asciimatics\renderers.py", line 276, in __init__
File "site-packages\pyfiglet__init__.py", line 710, in __init__
File "site-packages\pyfiglet__init__.py", line 717, in setFont
File "site-packages\pyfiglet__init__.py", line 90, in __init__
File "site-packages\pyfiglet__init__.py", line 100, in preloadFont
File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources__init__.py", line 1160, in resource_exists
File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources__init__.py", line 445, in get_provider
ImportError: No module named 'pyfiglet.fonts'
test returned -1
谷歌搜索这个错误返回 了这个线程,但在我看来这个错误是由 SublimeFiglet 本身的错误引起的,并且在两年前被修复了。
我在 Windows 10 上使用 Python 3.4。我不得不将 setuptools 降级到 19.2(我相信这是我必须降级到的版本),因为我收到一条错误消息,指出在尝试运行已编译的 .exe 时缺少打包包文件。
除了运行脚本所需的其他导入之外,我还导入了 test.py 中的六个(因为它是隐藏导入)和 pyfiglet 模块。导入 pyfiglet 和我能想到的任何变化都没有改变。我可以更改 spec 文件以添加一个隐藏的六个导入,但我看不出这会如何改变任何东西。
这是 Pyinstaller 使用的规范文件:
block_cipher = None
a = Analysis(['test.py'],
pathex=['C:\\Users\\Sirindil\\Documents\\Python Scripts\\asciimatics samples'],
binaries=None,
datas=None,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
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='test',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='test')
Asciimatics 包含的每个示例脚本都会为我返回同样的错误。在脚本上运行 pyinstaller 时,我尝试使用不同的选项,但没有成功。我错过了什么吗?我不知道如何解决这个问题。
原文由 James Burns 发布,翻译遵循 CC BY-SA 4.0 许可协议
我也遇到了同样的问题,我已经在 exe 中导入了 pyfiglet 文件夹,它对我有用。我将 venv 文件夹作为虚拟环境,但如果您有不同的虚拟环境文件夹名称,则也更改文件夹名称,否则只更改 AppName.py。