首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在不使用pyinstaller的情况下使用spacy为python程序创建一个exe文件?

如何在不使用pyinstaller的情况下使用spacy为python程序创建一个exe文件?
EN

Stack Overflow用户
提问于 2020-02-07 20:41:56
回答 2查看 738关注 0票数 0

我正在尝试打包我的Python程序,其中包含spacy。我尝试使用隐藏导入的pyinstaller,并创建了一个exe文件。但我总是得到以下错误:

代码语言:javascript
复制
 "FileNotFoundError: [Errno 2] No such file or directory: \\AppData\\Local\\Temp\\_MEI66162\\thinc\\neural\\_custom_kernels.cu'".

请帮助我解决这个问题,或者让我知道是否有任何其他方法来创建程序包文件。

代码语言:javascript
复制
Python : 3.7.0
Spacy: 2.2.3
EN

Stack Overflow用户

发布于 2021-02-02 22:38:53

你试过附加的钩子和扩展路径了吗?请参阅下面的链接

spacy 2.2.3 FileNotFoundError: [Errno 2] No such file or directory: 'thinc\neural\_custom_kernels.cu' in pyinstaller

它在正常(而不是虚拟环境)中对我有效。

FileNotFound错误是因为PyInstaller没有正确地打包thinc;thinc需要一个钩子。我发现包含from spacy import *的脚本可以与下面的钩子文件一起工作。我使用的命令是:

pyinstaller test-spacy.py y.py --additional-hooks-dir=.

只需将以下文本复制到一个名为hook- same y.py的文件中,该文件与您的脚本位于同一目录中。

代码语言:javascript
复制
# 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文件,它的工作。

代码语言:javascript
复制
# -*- 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')
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60113738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档