我正在使用 Pyinstaller 打包我的 python spacy 代码。我正在使用 de_core_news_sm 并通过 pip 安装它。正常脚本按预期执行,但一旦它与 pyinstaller 打包,它就找不到[E050] Can't find model 'de_core_news_sm'. It doesn't seem to be a Python package or a valid path to a data directory.
我为每个挂钩文件获得的模型:
from PyInstaller.utils.hooks import collect_all
# ----------------------------- blis -----------------------------
data = collect_all('blis')
datas = data[0]
binaries = data[1]
hiddenimports = data[2]
from PyInstaller.utils.hooks import collect_all
# ----------------------------- cymen -----------------------------
data = collect_all('cymem')
datas = data[0]
binaries = data[1]
hiddenimports = data[2]
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files("de_core_news_sm")
from PyInstaller.utils.hooks import collect_all
# ----------------------------- preshed -----------------------------
data = collect_all('preshed')
datas = data[0]
binaries = data[1]
hiddenimports = data[2]
from PyInstaller.utils.hooks import collect_all
# ----------------------------- SPACY -----------------------------
data = collect_all('spacy')
datas = data[0]
binaries = data[1]
hiddenimports = data[2]
from PyInstaller.utils.hooks import collect_all
# ----------------------------- thinc -----------------------------
data = collect_all('thinc')
datas = data[0]
binaries = data[1]
hiddenimports = data[2]
我使用以下 pyinstaller 命令:
pyinstaller script.py --hidden-import cmath --hidden-import srsly.msgpack.util
在这篇文章 [1] 中:使用 PyInstaller 打包时找不到 SpaCy 模型
这是从模块中添加数据文件的解决方案。那么我必须如何更改我的 script.py 运行时文件中的代码以及我必须如何更改挂钩文件?
顺便说一句,我在我的虚拟环境中使用:spacy 3.0.6、pyinstaller 4.3 和 python 3.8.0。
谢谢 !