2017-06-30 77 views
1

我嘗試使用cx_freeze我Tkinter的文件轉換爲EXE,但我得到這個錯誤所有的時間 the error轉換Tkinter的PY文件轉換成EXE文件

翻譯希伯來部分:模塊didnt發現

我安裝文件的代碼是:

import sys 
from cx_Freeze import setup, Executable 
import os 

os.environ['TCL_LIBRARY'] = "C:\\Users\\royreznik\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6" 
os.environ['TK_LIBRARY'] = "C:\\Users\\royreznik\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tk8.6" 


build_exe_options = {"includes": ["tkinter"]} 

base = None 
if sys.platform == "win32": 
    base = "Win32GUI" 

setup(
    name = "simple_Tkinter", 
    version = "0.1", 
    description = "Sample cx_Freeze Tkinter script", 
    options = {"build_exe": build_exe_options}, 
    executables = [Executable("tal1.py", base = base)]) 

和我的主要文件是:

from tkinter import * 
root = Tk() 


Entry1 = Entry(root) 
Entry2 = Entry(root) 

Entry1.grid(row=0) 
Entry2.grid(row=1) 

Label1 = Label(root, text="null") 
Label1.grid(row=4) 

def funca(): 
    phrase = Entry1.get() 
    words = phrase.split() 
    wordCount = 0; 
    for word in words: 
     if word == Entry2.get(): 
      wordCount = wordCount+1 
    Label1.configure(text=wordCount) 

btn = Button(root, text="get Num",command=funca) 
btn.grid(row=3) 



root.mainloop() 

最新的問題是什麼?

+0

我建議你使用'py2exe'庫 – CunivL

回答

1

在您的Python目錄的DLL文件夾中,您會找到tk86t.dlltcl86t.dll。您必須將它們複製到您要編譯的main.py的build文件夾中。

然後,您必須將這兩個文件添加到您的setup.py中的include_files參數中。現在

,你setup.py看起來應該是這樣的:

import os 
from cx_Freeze import setup, Executable 

os.environ['TCL_LIBRARY'] = 'c:/python36/tcl/tcl8.6' 
os.environ['TK_LIBRARY'] = 'c:/python36/tcl/tk8.6' 

buildOptions = dict(
    packages = [], 
    excludes = [], 
    include_files=['c:/python36/DLLs/tcl86t.dll', 'c:/python36/DLLs/tk86t.dll'] 
) 

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

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

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

當然,你可能不得不適應目錄的路徑,使其工作。

+0

非常感謝你!!!! – Reznik