[英]How to build single .exe file with multiple files in python using cx_freeze
[英]build python script to exe file using cx_freeze
我試圖將我的python腳本轉換為一個exe
文件,任何人都可以從任何計算機上運行它,包括沒有python的計算機。 因此,我看到一些解釋最佳方法的指南是在cx_freeze
庫中使用。 所以我建立了一個僅在tkinter中使用的小型gui應用程序,這是我的代碼:
import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
這是我的安裝文件:
from cx_Freeze import setup, Executable
setup(
name="GUI PROGRAM",
version="0.1",
description="MyEXE",
executables=[Executable("try.py", base="Win32GUI")],
)
我運行此命令:
python setup.py build
然后我得到這個錯誤:
KeyError: 'TCL_LIBRARY
而且只有在我使用tkinter時才會發生。 所以我想我想念一些東西,我需要以某種方式將tkinter添加到安裝文件中。 有人能幫我嗎? 非常感謝你們。
嘗試將安裝腳本更改為此:
from cx_Freeze import setup, Executable
import os
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
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')
files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path To Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter"]}
setup(
name="GUI PROGRAM",
version="0.1",
description="MyEXE",
options = {"build_exe": files},
executables=[Executable("try.py", base="Win32GUI")],
)
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')
將刪除錯誤消息,而files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path To Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter"]}
將包含缺少的Tk和Tcl運行時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.