Python到一个exe文件

问题描述 投票:-1回答:1

我正在尝试转换我的python文件,它使用的是 变压器, 空间感 为包,变成一个.exe文件。我已经尝试了cx_freeze和pyinstaller,但每次我尝试运行我生成的exe文件时,我分别面临以下错误。

对于 Pyinstaller:

    C:\Users\aishv\output>qa.exe
To use data.metrics please install scikit-learn. See https://scikit-learn.org/stable/index.html
Traceback (most recent call last):
  File "main.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\aishv\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\transformers\__init__.py", line 42, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\aishv\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\transformers\tokenization_auto.py", line 28, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\aishv\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\transformers\tokenization_xlm.py", line 27, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\aishv\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\sacremoses\__init__.py", line 2, in <module>
    """This directory is meant for IPython extensions."""
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\aishv\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\sacremoses\tokenize.py", line 16, in <module>
  File "site-packages\sacremoses\tokenize.py", line 23, in MosesTokenizer
  File "site-packages\sacremoses\corpus.py", line 63, in chars
  File "pkgutil.py", line 637, in get_data
  File "c:\users\aishv\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 471, in get_data
    with open(path, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\aishv\\AppData\\Local\\Temp\\_MEI228322\\sacremoses\\data\\perluniprops\\IsN.txt'
[23284] Failed to execute script main

对于cx_freeze:

Traceback (most recent call last):
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
    module.run()
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
    exec(code, {'__name__': '__main__'})
  File "main.py", line 1, in <module>
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\__init__.py", line 20, in <module>
    from .file_utils import (TRANSFORMERS_CACHE, PYTORCH_TRANSFORMERS_CACHE, PYTORCH_PRETRAINED_BERT_CACHE,
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\file_utils.py", line 20, in <module>
    import boto3
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\boto3\__init__.py", line 16, in <module>
    from boto3.session import Session
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\boto3\session.py", line 17, in <module>
    import botocore.session
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\session.py", line 30, in <module>
    import botocore.client
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 16, in <module>
    from botocore import waiter, xform_name
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\waiter.py", line 18, in <module>
    from botocore.docs.docstring import WaiterDocstring
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\docs\__init__.py", line 15, in <module>
    from botocore.docs.service import ServiceDocumenter
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\docs\service.py", line 18, in <module>
    from botocore.docs.bcdoc.restdoc import DocumentStructure
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\docs\bcdoc\restdoc.py", line 16, in <module>
    from botocore.docs.bcdoc.docstringparser import DocStringParser
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\docs\bcdoc\docstringparser.py", line 16, in <module>
    class DocStringParser(six.moves.html_parser.HTMLParser):
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\six.py", line 92, in __get__
    result = self._resolve()
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "C:\Users\aishv\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\six.py", line 82, in _import_module
    __import__(name)
ModuleNotFoundError: No module named 'html.parser'

请帮助我解决这个问题,这是我的Cx_freeze的安装文件。

from cx_Freeze import setup, Executable
setup(name='Qa',
        version='0.1',
        description='Application',
        executables = [Executable("main.py")])
pytorch pyinstaller cx-freeze torch huggingface-transformers
1个回答
0
投票

对于windows来说,使用这个,也是因为缺少依赖关系而导致的错误。

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('main.py', base=base)
]

setup(name='editor',
      version = '1.0',
      description = '',
      options = dict(build_exe = buildOptions),
      executables = executables)

试着创建一个虚拟环境,满足其中所有的依赖关系,然后创建exe文件。

© www.soinside.com 2019 - 2024. All rights reserved.