簡體   English   中英

運行用cx_freeze制作的tkinter exe時出錯

[英]Error on running tkinter exe made with cx_freeze

我正在嘗試使用cx_Freeze使用Python 3.5編寫的腳本創建獨立的exe,以便能夠在沒有Python的計算機上運行它。

該程序本身只是一個帶有tkinter的簡單UI的小型計算器。 我正在使用Windows 10。

我創建了一個如下所示的安裝腳本。

import sys
from cx_Freeze import setup, Executable
# replaces commandline arg 'build'
sys.argv.append("build")

filename = "Widgets_tmp.py"
base = None
if sys.platform == "win32":
    base = "Win32GUI"
setup(
    name = "Widgets",
    version = "1.0",
#   options={"build_exe": {"packages": ["tkinter"]}},
    description = "cx_Freeze Tkinter script",
    executables = [Executable(filename, base=base)])

直到我嘗試運行exe時,它才能正常運行。 然后我得到這個錯誤:

Traceback (most recent call last):
  File "C:\python64\lib\site-packages\cx_freeze\initscripts\Console.py"
line 21, in <module>
    exec(code, m.__dict__)
  File "Widgets_tmp.py", line 1, in <module>
  File "C:\python64\lib\tkinter\__init__.py", line 35, in <module>
    import _tkinter#If this fails you Python may not be configured for Tk
ImportError: DLL load failed:

我嘗試在代碼中注釋的代碼和“ includes”而不是“ packages”中將tkinter manualy包括在內,但結果相同。

也許我應該說Widgets_tmp.py中的第1行看起來像這樣:

import tkinter as tk

我嘗試凍結源代碼中的示例代碼,但收到相同的錯誤。 兩種代碼都可以使用python完美地工作。

我也嘗試使用:

options={"build_exe": {"includes": ["tkinter"]}},

但沒有運氣。

通過修改PC上的setup.py,可以正常運行tkinter exe。

操作系統= win7,Python = 3.5.2,cx_freeze = 5.0

setup.py:

includes      = []
include_files = [r"C:\Users\(USERNAME)\AppData\Local\Programs\Python\Python35-32\DLLs\tcl86t.dll", \
                 r"C:\Users\(USERNAME)\AppData\Local\Programs\Python\Python35-32\DLLs\tk86t.dll"]

setup(
    name = "Test",
    version = "1.0",
    options = {"build_exe": {"includes": includes, "include_files": include_files}},
    executables = [Executable("test.py", base=base)]
)

您必須為您的環境修改(USERNAME)。

暫無
暫無

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

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