使用 pyinstaller 将 python 脚本构建为单个 exe [英] build python script to single exe with pyinstaller
问题描述
我收到以下错误:脚本名称 = prepareIncidentCountMail.py
I am getting below errors : script name = 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
我在链接的帮助下使用熊猫风格:更改熊猫数据框中完整行的颜色
I am using pandas style with the help of link : Change color of complete row in data frame in pandas
我看到 style 正在使用 jinja2 导致上述错误.有没有办法挂钩这个错误或任何其他工具将python脚本转换为单个可执行文件.
I see style is using jinja2 causing the above error. Is there any way to hook this error or any other tool to convert python script into single executable.
推荐答案
我昨天刚刚使用 giumas 在这里所做的调整版本解决了这个问题:https://github.com/pyinstaller/pyinstaller/issues/1898
I just solved this myself yesterday using a tweaked version of what giumas did here: https://github.com/pyinstaller/pyinstaller/issues/1898
问题不是挂钩(这是我第一次尝试解决方案),而是熊猫样式模块导入 jinja2 的事实,它使用get_template"方法,而后者又使用 pkg_resources 模块.最后一个是问题,出于某种原因,pyinstaller 不能很好地与 pkg_resources 模块配合使用.
The issue isn't so much hooking (which was my first attempt at a solution), but the fact that pandas style module imports jinja2 which uses a "get_template" method which in turn uses the pkg_resources module. That last one is the issue, for some reason pyinstaller doesn't play well with the pkg_resources module.
解决方案:找到pandas的安装位置,然后去类似
Solution: Find where pandas is installed and go to something like
C:\Users\UserName\AppData\Local\Programs\Python\Python36\Lib\site-packages\pandas\io\formats
C:\Users\UserName\AppData\Local\Programs\Python\Python36\Lib\site-packages\pandas\io\formats
在格式文件夹中找到 style.py 文件并在您喜欢的文本编辑器中打开它.在 style.py 中向下滚动到第 118 行,您将在其中看到:
In the formats folder find the style.py file and open it in your favorite text editor. In style.py scroll down to about line 118 where you will see this:
template = env.get_template("html.tpl")
将此行更改为:
template = env.from_string("html.tpl")
保存文件并重新运行pyinstaller.当您尝试运行可执行文件时,它应该按预期执行,没有任何错误消息.
save the file and re-run pyinstaller. When you try and run the executable it should perform as expected sans any error messages.
希望有帮助.
这篇关于使用 pyinstaller 将 python 脚本构建为单个 exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!