【问题标题】:How to create a exe file for python program with spacy without using pyinstaller?如何在不使用pyinstaller的情况下为带有spacy的python程序创建exe文件?
【发布时间】:2020-02-07 12:41:55
【问题描述】:

我正在尝试打包包含 spacy 的 Python 程序。我尝试使用隐藏导入的 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

【问题讨论】:

  • 你的 setup.py 是什么样子的?
  • 我没有使用任何安装文件..我已经为其他程序创建了 exe 文件...

标签: python pyinstaller spacy


【解决方案1】:

我遇到了完全相同的问题,最终我放弃并将 spacy 回滚到版本 2.2.1,不知何故我能够在 pyinstaller 上编译我的程序而没有任何问题。

pip install spacy==2.2.1

【讨论】:

    【解决方案2】:

    您是否尝试过额外的钩子和扩展路径?见下方链接

    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 --additional-hooks-dir=.

    只需将以下文本复制到一个名为 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)
    

    同时调整 .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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      • 2016-12-29
      • 1970-01-01
      • 2019-07-18
      • 2019-09-15
      • 1970-01-01
      相关资源
      最近更新 更多