使用cx_Freeze将python文件(.py)转换为可执行文件(.exe)的问题 [英] Problems with python file(.py) to executable(.exe) with cx_Freeze

查看:75
本文介绍了使用cx_Freeze将python文件(.py)转换为可执行文件(.exe)的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更具体:该程序根本没有运行,仅打开命令提示符并突然关闭...
这是我的setup.py文件...
我导入了os并添加了tcl和tk的链接,以防止发生另一个问题。解决该问题后,现在我可以从原始python代码成功构建.exe,但是,当打开新创建的.exe文件...所有操作都将在短短毫秒内打开命令提示符屏幕,然后再次关闭。我假设tk.mainLoop()或tkinter通常可能存在一些构建错误?我还导入了数学模块和其他一些tkinter项,例如tkinter.font和tkinter.messagebox。
非常感谢您的帮助,我在cx_Freeze和python-to-executable程序/模块方面一直遇到很多问题...

TO BE MORE SPECIFIC: This program is not running AT ALL, only opening the command prompt and suddenly shutting down... Heres my setup.py file... I imported os and added the links to tcl and tk to prevent another issue for occurring. After solving that issue and now I am able to successfully build an .exe from my raw python code but, when opening the freshly created .exe file... All it will do it open a command prompt screen for mere milliseconds and close once again. I am assuming there was some build error possibly with tk.mainLoop() or tkinter in general? I am also importing the math module and a couple of other tkinter items such as tkinter.font and tkinter.messagebox. Would really appreciate the help, I've been having a TON of issues with cx_Freeze and python-to-executable programs/modules in general...

import os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = 'c:/python36-32/tcl/tcl8.6'
os.environ['TK_LIBRARY'] = 'c:/python36-32/tcl/tk8.6'
base = None


executables = [Executable("formulas_tkinter_replace2.py", base=base, icon="pi-outline-128.ico")]
packages = ["tkinter", "math"]
options = {
    'build_exe': {

        'packages':packages,
    },
}

setup(
    name = "Formula",
    version = "1.0",
    description = 'Mathematics made easy...',
    executables = executables
)


推荐答案

基本上,Tk和Tcl DLL都丢失了。您可以通过两种方式更正此错误。

Basically the Tk and Tcl DLL are both missing. There are two ways you correct this.

1)这更像是一种破解,仅在某些情况下可行,但在这种情况下,它应该:

1) This is more of a hack and only sometimes works but in this case it should:

tcl86t.dll tk86t.dll 从Python安装复制到您的位置可执行程序。这些可以在 Python36-32 / DLLs 中找到。就是这样。

Copy tcl86t.dll and tk86t.dll from your Python installation to the location of your exe. These can be found at Python36-32/DLLs. That's it.

2)做到这一点的正确方法是执行以下操作:
将其放在可执行文件之前:

2) The 'proper' way to do it would be to do something like this: Put this before executable:

files = {"include_files": ["C:/File_to_python/Python36-32/DLLs/tcl86t.dll", "C:/File_to_python/Python36-32/DLLs/tk86t.dll"]}

options = {
    'build_exe': {

        'packages':packages,
        'build_exe':files 
    },
}

代替以前的文件。

编辑:对。该脚本应该起作用。我完全重写了您提供的安装脚本,但是基本上您所做的是正确的,但是由于未找到文件 tcl8.6 而出现错误,并且您也忘记了使用 include_files 函数。不过,这可以手动完成。

Right. This script should work. I completely rewrote the setup script you provided however essentially what you did is correct however the error appeared because the file tcl8.6 was not found and you also forgot to use the include_files function. This can be done manually though.

from cx_Freeze import setup, Executable

import os
os.environ['TCL_LIBRARY'] = "FilePathToPython/Python36-32/tcl/tcl8.6"
os.environ['TK_LIBRARY'] = "FilePathToPython/Python36-32/tcl/tk8.6"
files = {"include_files":["FilePathToPython/Python36-32/DLLs/tcl86t.dll", "FilePathToPython/Python36-32/DLLs/tk86t.dll", "pi-outline-128.ico"], "packages": ["tkinter"]}

base = None
setup( name = "Name of exe",
       version = "0.0",
       author = "Reader",
       description = "compile with setup.py build",
       options = {"build_exe": files},
       executables = [Executable("formulas_tkinter_replace2.py", icon="pi-outline-128.ico", base=base)])

只需替换您需要的内容。

Just replace what you need to.

我已经说过。您可以使用 base ='Win32GUI'

As I already said. You can hide the console completely by using base = 'Win32GUI'

这篇关于使用cx_Freeze将python文件(.py)转换为可执行文件(.exe)的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆