0

是否有可能,有人可以发布一个包含 spacy 和语言模型的最小程序的工作pyinstaller示例?

我尝试按照 stackoverflow 上的提示进行操作,但也许我不太了解它们。我仍然收到相同的错误,即找不到模型。

4

1 回答 1

1

我能够使用 PyInstaller 使用 Spacy 2.x 打包我的“预测服务器”,但需要大量试验才能使所有“钩子”正确。我的预测服务器加载 NR 模型并(在套接字上)侦听预测请求(数据)。对于每个请求,它返回预测的 NR 实体。

我让我的服务器在不使用 GPU 的情况下工作。添加 GPU 支持会导致一个怪物可执行文件,它总是缺少一些东西 - 更不用说它可能只能移植到具有相同 CUDA 版本的机器上。

我的 SpacyServer.spec:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['SpacyServer.py'],
             pathex=['C:\\Work\\ML\\Spacy\\deploy'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=['.'],
             runtime_hooks=[],
             excludes=['cupy'],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='SpacyServer',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

还有我的 hook-spacy.py:

# HOOK FILE FOR SPACY
from PyInstaller.utils.hooks import collect_all

# ----------------------------- SPACY -----------------------------
print('=================== SPACY =====================')
data = collect_all('spacy')

datas = data[0]
binaries = data[1]
hiddenimports = data[2]

# ----------------------------- THINC -----------------------------
data = collect_all('thinc')

datas += data[0]
binaries += data[1]
hiddenimports += data[2]

# ----------------------------- CYMEM -----------------------------
data = collect_all('cymem')

datas += data[0]
binaries += data[1]
hiddenimports += data[2]

print(data[2])

# ----------------------------- PRESHED -----------------------------
data = collect_all('preshed')

datas += data[0]
binaries += data[1]
hiddenimports += data[2]

# ----------------------------- BLIS -----------------------------

data = collect_all('blis')

datas += data[0]
binaries += data[1]
hiddenimports += data[2]

# ----------------------------- OTHER ----------------------------

hiddenimports += ['srsly.msgpack.util']

# This hook file is a bit of a hack - really, all of the libraries should be in seperate hook files. (Eg hook-blis.py with the blis part of the hook)
# But it looks we need to process everything when we import spacy, else we do not even hit import cymem.

print('=================== SPACY DONE =====================')

最后,我运行:

pyinstaller   --onefile   --name SpacyServer SpacyServer.py  --additional-hooks-dir=. --exclude-module=cupy
于 2021-07-21T21:42:22.650 回答