gpt4 book ai didi

python - cx_Freeze 缺少模块

转载 作者:行者123 更新时间:2023-12-01 08:22:21 30 4
gpt4 key购买 nike

我正在使用 python 3.7 和 cx_Freeze 5.1.1 ,我试图将我的 python 脚本转换为可执行文件,但我遇到了丢失模块错误,我被难住了。

我尝试将模块放入包中并包含安装脚本,但没有任何变化。

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
# build_exe_options = {"packages": ["os", "win32api", "win32con", "pywintypes", "easyguy", "ntsecuritycon"
# , "win32security", "errno", "shutil", "ctypes"], "excludes": ["tkinter"],
# "includes" = ['easy_gui']}

build_exe_options = {'packages': ['sys', "os", "win32api", "win32con",
"pywintypes", "easygui", "ntsecuritycon",
"errno", "shutil", "ctypes", "win32security",
"errno", "shutil", "ctypes"],
'excludes': ['tkinter'],
'includes': ["os", "win32api", "win32con", "pywintypes",
"easygui", "ntsecuritycon",
"errno", "shutil", "ctypes", "win32security",
"errno", "shutil", "ctypes"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"

setup(name="Automated Installer", # this will set the name of the created executable to "Automated Installer.exe"
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("Automated Installer.py", base=base)]) # this tells cx_Freeze to freeze the script "Automated Installer.py"

我希望创建一个可执行文件,但我却抛出了这个错误\

ImportError: No module named 'win32api'

编辑 2:反射(reflect)下面发布的答案所采取的步骤。

我升级回 Python 3.7,并按照建议对 freeze.py 应用了修复。我采用了完全相同的 easygui 脚本,并在下面编写了相同的 setup.py 脚本。可执行文件会生成,但不会运行。我收到如下所示的错误。我能够很好地运行示例 easygui 脚本,因此我相信 easygui 已正确安装。

Error popup when executable created is run

我不太确定完整堆栈跟踪是什么意思,但这里是我收到的命令提示符的一些值得注意的输出

Missing modules:
? __main__ imported from bdb, pdb
? _frozen_importlib imported from importlib, importlib.abc
? _frozen_importlib_external imported from importlib, importlib._bootstrap,
importlib.abc
? _posixsubprocess imported from subprocess
? _winreg imported from platform
? easygui imported from hello world__main__
? grp imported from shutil, tarfile
? java.lang imported from platform
? org.python.core imported from copy, pickle
? os.path imported from os, pkgutil, py_compile, tracemalloc, unittest,
unittest.util
? posix imported from os
? pwd imported from http.server, posixpath, shutil, tarfile, webbrowser
? termios imported from tty
? vms_lib imported from platform
This is not necessarily a problem - the modules may not be needed on this
platform.

running build
running build_exe
copying C:\Users\Billy\AppData\Local\Programs\Python\Python37\lib\site-
packages\cx_Freeze\bases\Win32GUI.exe -> build\exe.win-amd64-3.7\hello
world.exe
copying
C:\Users\Billy\AppData\Local\Programs\Python\Python37\python37.dll ->
build\exe.win-amd64-3.7\python37.dll
copying
C:\Users\Billy\AppData\Local\Programs\Python\Python37\VCRUNTIME140.dll ->
build\exe.win-amd64-3.7\VCRUNTIME140.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-runtime-l1-1-0.dll -
>
build\exe.win-amd64-3.7\api-ms-win-crt-runtime-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-stdio-l1-1-0.dll ->
build\exe.win-amd64-3.7\api-ms-win-crt-stdio-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-math-l1-1-0.dll ->
build\exe.win-amd64-3.7\api-ms-win-crt-math-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-locale-l1-1-0.dll ->
build\exe.win-amd64-3.7\api-ms-win-crt-locale-l1-1-0.dll
copying C:\Program Files\TortoiseGit\bin\api-ms-win-crt-heap-l1-1-0.dll ->
build\exe.win-amd64-3.7\api-ms-win-crt-heap-l1-1-0.dll
*** WARNING *** unable to create version resource
install pywin32 extensions first
writing zip file build\exe.win-amd64-3.7\lib\library.zip

最佳答案

  1. cx_Freeze 尚不支持 Python 3.7,它有一个错误。存在错误修复但尚未发布,但是您可以手动应用它,请参阅 What could be the reason for fatal python error:initfsencoding:unable to load the file system codec?Cx_freeze crashing Python3.7.0 。或者,如果您可以选择,您也可以回滚到 Python 3.6。

编辑:

  • 检查 easygui 是否已正确安装。例如,您应该能够从 easygui documentation 运行以下 hello.py 示例脚本。 :

    from easygui import *
    import sys

    # A nice welcome message
    ret_val = msgbox("Hello, World!")
    if ret_val is None: # User closed msgbox
    sys.exit(0)

    msg = "What is your favorite flavor?\nOr Press <cancel> to exit."
    title = "Ice Cream Survey"
    choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
    while 1:
    choice = choicebox(msg, title, choices)
    if choice is None:
    sys.exit(0)
    msgbox("You chose: {}".format(choice), "Survey Result")
  • 尝试卡住此示例脚本。 easygui 依赖于 tkinter,它需要一些额外的调整才能使用 cx_Freeze 5.1.1 卡住,请参阅 tkinter program compiles with cx_Freeze but program will not launch 。您应该能够使用以下设置脚本卡住该示例:

    from cx_Freeze import setup, Executable
    import os
    import sys

    PYTHON_INSTALL_DIR = os.path.dirname(sys.executable)
    os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
    os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

    build_exe_options = {'include_files': [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
    os.path.join('lib', 'tk86t.dll')),
    (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
    os.path.join('lib', 'tcl86t.dll'))]}

    # GUI applications require a different base on Windows (the default is for a
    # console application).
    base = None
    if sys.platform == 'win32':
    base = 'Win32GUI'

    setup(name='hello',
    version='0.1',
    description='Sample cx_Freeze EasyGUI script',
    executables=[Executable('hello.py', base=base)],
    options={'build_exe': build_exe_options})
  • 关于python - cx_Freeze 缺少模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54542382/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com