程序在运行时工作:
Python filename.py
但是当我使用"pyinstaller"创建其可执行文件时
pyinstaller -F filename.py
可执行文件已成功创建,但脚本执行失败并引发以下错误。
Traceback (most recent call last):
File "site-packagespyexcel_iomanager.py", line 160, in create_reader
File "site-packagespyexcel_iomanager.py", line 222, in _get_a_handler
pyexcel_io.manager.NoSupportingPluginFound: No suitable library found for xls
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "script.py", line 8, in <module>
File "site-packagespyexcel_xls__init__.py", line 29, in get_data
File "site-packagespyexcel_ioio.py", line 36, in get_data
File "site-packagespyexcel_ioio.py", line 126, in load_data
File "site-packagespyexcel_iomanager.py", line 171, in create_reader
pyexcel_io.manager.SupportingPluginAvailableButNotInstalled: Please install pyexcel-xls
Failed to execute script script
相应的 python 脚本是:
from pyexcel_xls import save_data , get_data
data = get_data("registered-market-makers-by-security.xls")
save_data("file_to_consume.xls", data)
如何避免此错误并创建功能性.exe文件?
我的客户端有窗口环境。
我也尝试过py2exe,但它与我的机器中的Windows dll有一些冲突。
问题
pyexcel-io
使用一种方法来包含 pyinstaller 不支持的插件。 请参阅此问题。
解决方法
此问题的解决方法有几个方面。
需要对 pyexcel 进行更改
我已经提交了一份更改请求,其中显示了如何修改pyexcel以允许它与pyinstaller一起使用。 基本上pyexcel-io需要知道如何找到冻结的模块。
如果pyexcel的人拿起了更改请求,那么这将让你开始。 但是,如果他们不这样做,或者您很着急,那么将更改的文件从更改请求复制到您的网站包目录中,就像pyexcel_io/__init__.py
一样将使pyexcel正常工作。
但是,pyinstaller 还需要知道要包含的内容。
pyinstaller 还需要知道包含所需的模块。 因此,在pyinstaller命令行上,您还需要执行以下操作:
--hidden-import pyexcel_xls.xls
更新:
具有此修复程序的更改请求已合并到 pyexcel 的主分支中。
更新#2:
修复程序已发布到 pypi。
对我来说,这个二人组:
(1) --隐藏导入 pyexcel_xlsx.xlsxr(我只是想在 pyinstaller 命令中读取 xls)
和(重要!
(2)在主文件中添加"导入pyexcel_xlsx.xlsxr">
对于"ODS"也是如此; 对于 csv:"--隐藏导入pyexcel_io.readers.csv_in_file"/"import pyexcel_io">
我在使用py2exe 代替 pyinstaller时遇到了同样的问题。 在对我的代码进行了一些研究和一些谷歌搜索后,我最终进入了这个线程,发现问题是相似的,解决方案也是如此。 如果这对其他人有任何帮助,为了使用pyexcel
库生成具有py2exe
的可执行文件,我在py2exe设置选项的包含section
中添加了'pyexcel_xls.xls'
和'pyexcel_xlsx.xlsx'
。所以:
setup(
name='Hello'
version='0.1'
description='Hello program'
author='Me'
options={
'compressed': 1
'optimized': 1
'includes': ['pyexcel_xls.xls', 'pyexcel_xlsx.xlsx' ...]
}
console=['hello.py']
)