簡體   English   中英

cx_Freeze 缺少模塊

[英]cx_Freeze missing module

我正在使用 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:反映下面發布的答案所采取的步驟。

我升級回 Python 3.7,並按照建議將修復程序應用到 f​​reezer.py。 我采用了完全相同的 easygui 腳本和同樣的 setup.py 腳本也在下面編寫。 可執行文件生成,但不運行。 我被拋出如下所示的錯誤。 我能夠很好地運行示例 easygui 腳本,因此我相信 easygui 已正確安裝。

運行創建的可執行文件時彈出錯誤

我不太確定您所說的完整堆棧跟蹤是什么意思,但這是我收到的命令提示符的一些值得注意的輸出

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,它有一個錯誤。 存在錯誤修復但尚未發布,但是您可以手動應用它,請參閱致命 python 錯誤的原因可能是什么:initfsencoding:無法加載文件系統編解碼器? Cx_freeze 崩潰 Python3.7.0 或者,如果這是您的選擇,您可以回滾到 Python 3.6。

編輯:

  1. 檢查是否正確安裝了easygui 例如,您應該能夠從easygui 文檔中運行以下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")
  2. 嘗試凍結此示例腳本。 easygui取決於tkinter ,這需要一些額外的調整與凍結cx_Freeze 5.1.1,請與cx_Freeze的Tkinter程序編譯,但程序不會啟動 您應該能夠使用以下設置腳本凍結示例:

     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})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM