python-3.x之使用 pyinstaller 将 python 脚本构建为单个 exe
我遇到以下错误:脚本名称 = prepareIncidentCountMail.py
Traceback (most recent call last):
File "Alexa\prepareIncidentCountMail.py", line 52, in <module>
File "site-packages\pandas\core\frame.py", line 683, in style
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\avikumar\documents\learn\alexa\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pandas\io\formats\style.py", line 50, in <module>
File "site-packages\pandas\io\formats\style.py", line 118, in Styler
File "site-packages\jinja2\environment.py", line 830, in get_template
File "site-packages\jinja2\environment.py", line 804, in _load_template
File "site-packages\jinja2\loaders.py", line 113, in load
File "site-packages\jinja2\loaders.py", line 234, in get_source
File "site-packages\pkg_resources\__init__.py", line 1459, in has_resource
File "site-packages\pkg_resources\__init__.py", line 1509, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
[10536] Failed to execute script prepareIncidentCountMail
我在链接的帮助下使用 Pandas 风格: Change color of complete row in data frame in pandas
我看到样式正在使用 jinja2 导致上述错误。有没有办法 Hook 这个错误或任何其他工具来将 python 脚本转换为单个可执行文件。
请您参考如下方法:
我昨天刚刚使用 giumas 在这里所做的调整版本自己解决了这个问题:https://github.com/pyinstaller/pyinstaller/issues/1898
问题不在于 Hook (这是我第一次尝试解决方案),而是 pandas 样式模块导入 jinja2 的事实,它使用“get_template”方法,而后者又使用 pkg_resources 模块。最后一个是问题,由于某种原因 pyinstaller 不能很好地与 pkg_resources 模块配合使用。
解决方案:找到 pandas 的安装位置,然后转到类似
C:\Users\UserName\AppData\Local\Programs\Python\Python36\Lib\site-packages\pandas\io\formats
在格式文件夹中找到 style.py 文件并在您喜欢的文本编辑器中打开它。在 style.py 中向下滚动到第 118 行,您将在其中看到:
template = env.get_template("html.tpl")
将此行更改为:
template = env.from_string("html.tpl")
保存文件并重新运行 pyinstaller。当您尝试运行可执行文件时,它应该按预期执行,没有任何错误消息。
希望能帮助到你。
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。