Python:构建后的CX_Freeze问题。

时间:2021-02-07 18:01:43

I created a small converter and after building it with CX_Freeze it shows this error

我创建了一个小的转换器,在用CX_Freeze构建它之后,它显示了这个错误。

Traceback (most recent call last): File "C:\users\LDC\AppData\Local\Programs\python\python36-32\lib\sitr\e-packages\cx_freeze\initscripts_startup_.py", line14 in run module.run() File "C:\users\LDC\AppData\Local\Programs\python\python36-32\lib\sitr\e-packages\cx_freeze\initscripts\console.py", line26 in run exec(code,m.dict) File"GUI1.py",line 1, in File "C:\USERS\LDC\APPDATA\LOCAL\PROGRAMS\PYTHON\PYTHON36-32\LIB\TKINTER_INIT_.PY",line36,in import_tkinter#If this fails your python may not be configured for Tk ImportError: DLL load failed: the specified module could not be found

Traceback(最近的调用):File "C:\users\LDC\AppData\ \ \ \python\python36-32\ \ \ \ \ \ \ \ - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \。在运行模块中,运行()文件“C:\ \用户\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ - \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \在运行exec(代码,m.dict)文件“GUI1”中。py“,第1行,在文件中”C:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ * \ \ \ \ \ \ \ \ - \ \ \ \ \ \ - \ \ \ \ \ \ \ \ \ \ \ \在import_tkinter#中,如果这个失败,您的python可能没有配置为Tk impor恐怖:DLL加载失败:无法找到指定的模块。

This is a screen shot from the error

这是一个错误的屏幕截图。

Now this is my code:

这是我的代码:

from tkinter import *
window1=Tk()

def convert():
    var2=var1.get()
    var3=var2*3.785
    e2.insert(0,var3)

def clear():
    e1.delete(0,END)
    e2.delete(0,END)

def quit():
    window1.destroy()

var1=IntVar()
label1=Label(window1,text='Gallons',padx=25).grid(row=0,sticky=W)
e1=Entry(window1,width=25,textvariable=var1)
e1.grid(row=0,column=1)
label2=Label(window1,text='Liters',padx=25).grid(row=1,sticky=W)
e2=Entry(window1,width=25)
e2.grid(row=1,column=1)

window1.title("Converter")
window1.geometry("400x200+200+200")
button1= Button(text='convert',command=convert,width=15,).grid(row=4,column=0)
button2= Button(text='clear',command=clear,width=15).grid(row=4,column=1)
button3= Button(text='exit',command=quit,width=15).grid(row=5,column=1)

mymenu=Menu()
mymenu.add_cascade(label='File')
mymenu.add_cascade(label='Edit')
mymenu.add_cascade(label='View')
mymenu.add_cascade(label='Tools')
mymenu.add_cascade(label='Help')
window1.config(menu=mymenu)

window1.mainloop()

and this is the setup code

这是设置代码。

import cx_Freeze
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')

base = None

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

executables = [cx_Freeze.Executable("GUI1.py", base=base, icon="clienticon.ico")]

cx_Freeze.setup(
    name = "GUI1",
    options = {"build_exe": {"packages":["tkinter"], "include_files":["clienticon.ico"]}},
    version = "0.01",
    description = "Ya Rb",
    executables = executables
    )

I tried the following with no luck: 1. uninstalled cx freeze and installed it again 2. tried different version of python .. python 2.7 3. tried to use py2exe and pyinstaller got different errors 4. also made sure that the python path in the environment is set correctly

我试了一下,没有运气:1。卸载的cx冻结并重新安装它2。尝试了不同版本的python。python 2.7 3。尝试使用py2exe和pyinstaller有不同的错误4。还要确保正确地设置了环境中的python路径。

Thanks in advance appreciate your help..

谢谢你的帮助。

1 个解决方案

#1


0  

This error is not as bad as it looks. You just need to know the path to your Python installation.

这个错误并不像看上去的那么糟。您只需要知道Python安装的路径。

What the error means: you've included the tkinter library but forgotten the tkinter run-times (tk86t.dll and tcl86t.dll). For your script to work you need to include them.

错误的含义是:您已经包含了tkinter库,但忘记了tkinter运行时(tk86t)。dll和tcl86t.dll)。要让脚本工作,您需要包含它们。

This can be done with the use of include_files statement. A quick search through the installation reveals they are located in a folder called DLLs. We need to give the file path and the file names we want to the setup script. This can be done like this:

这可以通过使用include_files语句完成。通过安装快速搜索显示,它们位于一个名为dll的文件夹中。我们需要给出文件路径和我们想要设置脚本的文件名。可以这样做:

  "include_files":["<path to python>/Python36-32/DLLs/tcl86t.dll","<path to python>/Python36-32/DLLs/tk86t.dll"]

and it will now work.

它现在可以工作了。

Your setup script will look like this:

您的安装脚本将如下所示:

import cx_Freeze
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')

base = None

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

executables = [cx_Freeze.Executable("GUI1.py", base=base, icon="clienticon.ico")]

cx_Freeze.setup(
    name = "GUI1",
    options = {"build_exe": {"packages":["tkinter"], "include_files":["clienticon.ico", "<path to python>/Python36-32/DLLs/tcl86t.dll","<path to python>/Python36-32/DLLs/tk86t.dll"]}},
    version = "0.01",
    description = "Ya Rb",
    executables = executables
    )

#1


0  

This error is not as bad as it looks. You just need to know the path to your Python installation.

这个错误并不像看上去的那么糟。您只需要知道Python安装的路径。

What the error means: you've included the tkinter library but forgotten the tkinter run-times (tk86t.dll and tcl86t.dll). For your script to work you need to include them.

错误的含义是:您已经包含了tkinter库,但忘记了tkinter运行时(tk86t)。dll和tcl86t.dll)。要让脚本工作,您需要包含它们。

This can be done with the use of include_files statement. A quick search through the installation reveals they are located in a folder called DLLs. We need to give the file path and the file names we want to the setup script. This can be done like this:

这可以通过使用include_files语句完成。通过安装快速搜索显示,它们位于一个名为dll的文件夹中。我们需要给出文件路径和我们想要设置脚本的文件名。可以这样做:

  "include_files":["<path to python>/Python36-32/DLLs/tcl86t.dll","<path to python>/Python36-32/DLLs/tk86t.dll"]

and it will now work.

它现在可以工作了。

Your setup script will look like this:

您的安装脚本将如下所示:

import cx_Freeze
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')

base = None

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

executables = [cx_Freeze.Executable("GUI1.py", base=base, icon="clienticon.ico")]

cx_Freeze.setup(
    name = "GUI1",
    options = {"build_exe": {"packages":["tkinter"], "include_files":["clienticon.ico", "<path to python>/Python36-32/DLLs/tcl86t.dll","<path to python>/Python36-32/DLLs/tk86t.dll"]}},
    version = "0.01",
    description = "Ya Rb",
    executables = executables
    )