0.52.0版本打包为 exe 后报错,0.51.0版本不存在该问题。
运行环境
- 操作系统(Windows):
- Python 版本:3.8.8
- pypinyin 版本:0.52.0
问题描述
使用 pyinstaller 将 python file 打包为一个 exe 文件,文件中使用了lazy_pinyin。未打包文件能够正常运行,打包文件在0.52.0版本会一直报错 no such file or dictionary: pinyin_dict.json。
而在0.51.0版本则一切正常。
问题复现步骤
将 python 文件使用 pyinstaller 打包为 exe 文件运行即可。
@eclipseIs-73 可以试试 https://pyinstaller.org/en/stable/runtime-information.html#placing-data-files-at-expected-locations-inside-the-bundle 这里介绍的方法:修改 app.spec 文件中的 datas 配置:
from PyInstaller.utils.hooks import collect_data_files // 新增
a = Analysis(
['main.py'],
datas=collect_data_files('pypinyin'), // 修改这个
....
)
如果原先是 data=resources,可以在之前加上一行 resources += collect_data_files('pypinyin')
@mozillazg 请问能在近期做一个 release 来让我的PR生效吗,我在自己的程序里也有这个问题,目前是按照这里的方法凑合的,生效的话我也能早点把这个 workaround 去掉,其他人也不再会碰到一样的问题。
@xushengj 我争取周末的时候发布一个新版本。
@xushengj 新版本已发布。感谢 @xushengj 的贡献,使用新版本后不再需要修改 spec 文件或者增加 --collect-data 参数。