使用pyinstaller将python脚本构建到单个exe

问题描述 投票:2回答:1

我收到以下错误:脚本名称= 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

我在链接:Change color of complete row in data frame in pandas的帮助下使用熊猫风格

我看到样式使用jinja2导致上述错误。有没有办法挂钩此错误或任何其他工具将python脚本转换为单个可执行文件。

python-3.x pandas pyinstaller
1个回答
2
投票

我昨天使用giumas在这里做的调整版本来解决这个问题:https://github.com/pyinstaller/pyinstaller/issues/1898

问题不是挂钩(这是我第一次尝试解决方案),而是pandas样式模块导入jinja2的事实,它使用“get_template”方法,后者又使用pkg_resources模块。最后一个是问题,由于某种原因,pyinstaller与pkg_resources模块不兼容。

解决方案:找到安装pandas的地方并转到类似的地方

C:\ Users \用户名\ AppData \本地\程序\ Python的\ Python36 \ LIB \站点包\大熊猫\ IO \格式

在formats文件夹中找到style.py文件并在您喜欢的文本编辑器中打开它。在style.py中向下滚动到第118行,您将看到:

template = env.get_template("html.tpl")

将此行更改为:

template = env.from_string("html.tpl")

保存文件并重新运行pyinstaller。当您尝试运行可执行文件时,它应该按预期执行任何错误消息。

希望能帮助到你。

© www.soinside.com 2019 - 2024. All rights reserved.