我正在尝试打包我的Python程序,其中包含spacy。我尝试使用隐藏导入的pyinstaller,并创建了一个exe文件。但我总是得到以下错误:
"FileNotFoundError: [Errno 2] No such file or directory: \\AppData\\Local\\Temp\\_MEI66162\\thinc\\neural\\_custom_kernels.cu'".请帮助我解决这个问题,或者让我知道是否有任何其他方法来创建程序包文件。
Python : 3.7.0
Spacy: 2.2.3发布于 2021-02-02 22:38:53
你试过附加的钩子和扩展路径了吗?请参阅下面的链接
它在正常(而不是虚拟环境)中对我有效。
FileNotFound错误是因为PyInstaller没有正确地打包thinc;thinc需要一个钩子。我发现包含from spacy import *的脚本可以与下面的钩子文件一起工作。我使用的命令是:
pyinstaller test-spacy.py y.py --additional-hooks-dir=.
只需将以下文本复制到一个名为hook- same y.py的文件中,该文件与您的脚本位于同一目录中。
# HOOK FILE FOR SPACY
from PyInstaller.utils.hooks import collect_all
# ----------------------------- 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]
# ----------------------------- 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]
# 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)还调整了.spec文件,并添加了以下细节的main.spec文件,它的工作。
# -*- mode: python ; coding: utf-8 -*-
import PyInstaller
datas = []
datas.extend(PyInstaller.utils.hooks.collect_data_files('spacy.lang', include_py_files = True))
datas.extend(PyInstaller.utils.hooks.collect_data_files('thinc'))
block_cipher = None
a = Analysis(['main.py'],
pathex=['D:\\rajesh\\python\\console\\live'],
binaries=[],
datas=datas,
hiddenimports = [
'spacy.kb',
'spacy.lexeme',
'spacy.matcher._schemas',
'spacy.morphology',
'spacy.parts_of_speech',
'spacy.syntax._beam_utils',
'spacy.syntax._parser_model',
'spacy.syntax.arc_eager',
'spacy.syntax.ner',
'spacy.syntax.nn_parser',
'spacy.syntax.stateclass',
'spacy.syntax.transition_system',
'spacy.tokens._retokenize',
'spacy.tokens.morphanalysis',
'spacy.tokens.underscore',
'spacy._align',
'blis',
'blis.py',
'cymem',
'cymem.cymem',
'murmurhash',
'murmurhash.mrmr',
'preshed.maps',
'srsly.msgpack.util',
'thinc.extra.search',
'thinc.linalg',
'thinc.neural._aligned_alloc',
'thinc.neural._custom_kernels',
'sklearn.utils._cython_blas',
'sklearn.neighbors.typedefs',
'sklearn.neighbors.quad_tree',
'sklearn.tree._utils'
],
hookspath=[],
runtime_hooks=[],
excludes=[],
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,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,/
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main')https://stackoverflow.com/questions/60113738
复制相似问题