[英]How to create a exe file for python program with spacy without using pyinstaller?
I am trying to package my Python program which contains spacy.我正在尝试打包包含 spacy 的 Python 程序。 I tried with pyinstaller using hidden imports and created a exe file.我尝试使用隐藏导入的 pyinstaller 并创建了一个 exe 文件。 But I am always getting the following error:但我总是收到以下错误:
"FileNotFoundError: [Errno 2] No such file or directory: \\AppData\\Local\\Temp\\_MEI66162\\thinc\\neural\\_custom_kernels.cu'".
Please Help me with this problem or let me know if there is any other way to create package file..请帮我解决这个问题,或者让我知道是否有任何其他方法来创建包文件..
Python : 3.7.0
Spacy: 2.2.3
我遇到了完全相同的问题,最终我放弃了并将 spacy 回滚到 2.2.1 版,并且不知何故我能够在 pyinstaller 上编译我的程序而没有任何问题。
pip install spacy==2.2.1
Have you tried the additional hooks and extended paths?您是否尝试过额外的钩子和扩展路径? See link below见下面的链接
spacy 2.2.3 FileNotFoundError: [Errno 2] No such file or directory: 'thinc\\\\neural\\\\_custom_kernels.cu' in pyinstaller spacy 2.2.3 FileNotFoundError:[Errno 2] 没有这样的文件或目录:pyinstaller 中的“thinc\\\\neural\\\\_custom_kernels.cu”
It worked for me in a normal (not a virtual environment).它在正常(不是虚拟环境)中对我有用。
The FileNotFound error is because PyInstaller isn't packaging thinc properly; FileNotFound 错误是因为 PyInstaller 没有正确打包 Thinc; thinc needed a hook. Thinc 需要一个钩子。 I've found that as script containing from spacy import * will work with the hook file below.我发现包含 from spacy import * 的脚本可以与下面的钩子文件一起使用。 The command I used was:我使用的命令是:
pyinstaller test-spacy.py --additional-hooks-dir=. pyinstaller test-spacy.py --additional-hooks-dir=.
Simply copy the below text into a file called hook-spacy.py, that's in the same directory as your script.只需将以下文本复制到名为 hook-spacy.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)
Also adjust .spec file and added main.spec file with below details and it works.还调整 .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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.