python-pinyin icon indicating copy to clipboard operation
python-pinyin copied to clipboard

0.52.0版本打包为 exe 后报错,0.51.0版本不存在该问题。

Open eclipseIs-73 opened this issue 1 year ago • 1 comments

运行环境

  • 操作系统(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 avatar Aug 16 '24 08:08 eclipseIs-73

@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'),   //  修改这个
    ....
)

mozillazg avatar Aug 16 '24 13:08 mozillazg

如果原先是 data=resources,可以在之前加上一行 resources += collect_data_files('pypinyin')

szh-bash avatar Sep 06 '24 07:09 szh-bash

@mozillazg 请问能在近期做一个 release 来让我的PR生效吗,我在自己的程序里也有这个问题,目前是按照这里的方法凑合的,生效的话我也能早点把这个 workaround 去掉,其他人也不再会碰到一样的问题。

xushengj avatar Sep 09 '24 21:09 xushengj

@xushengj 我争取周末的时候发布一个新版本。

mozillazg avatar Sep 10 '24 04:09 mozillazg

@xushengj 新版本已发布。感谢 @xushengj 的贡献,使用新版本后不再需要修改 spec 文件或者增加 --collect-data 参数。

mozillazg avatar Sep 15 '24 08:09 mozillazg