【问题标题】:Python Error using Tkinter tix when create exe or msi with cx_Freeze使用 cx_Freeze 创建 exe 或 msi 时使用 Tkinter tix 的 Python 错误
【发布时间】:2021-11-30 03:10:46
【问题描述】:

我正在尝试使用 Python 制作我的脚本的 EXE/MSI,但在我的脚本中我使用库 tkinter.tix 我使用它来创建气球工具提示。如果我使用 IDLE 执行脚本运行良好,但如果我尝试制作 EXE(auto-py-to-exe) 或 MSI(cx_Freeze),则会显示错误。

我这样导入模块:

from tkinter.tix import *

我附上图片中的错误。

我很感激你能帮助我!!!谢谢...

【问题讨论】:

  • 这个question 可能会有所帮助。
  • 在 Stackoverflow 上有很多类似的问题,而且总是同样的问题:Python 不是为了构建 .exe 而创建的,PyInstalle、cx_Freeze 等工具可能有问题要查找所有需要的 Python 模块和 C/C++ 库 - 然后您必须手动将它们添加到项目中。 PyInstaller 对此有特殊文件 .spec。在PyInstaller 文档中,您可以找到页面"Using Spec File" 和"What to do when something goes wrong"
  • 您的错误表明它无法找到 C/C++ 库 libtix.8.1.8.3.so 或类似库(因为 .so 表示 Linux 的库)-因此您必须手动将其添加到项目中。您必须在文档中找到详细信息。

标签: python tkinter cx-freeze


【解决方案1】:

您还需要将Python安装文件夹中的tix文件夹复制到分布式文件夹中。

以下是使用cx_Freeze 时的setup.py 示例:

from cx_Freeze import setup, Executable

# change to the correct path for the tix folder in your system
include_files = [(r'C:\Python38\tcl\tix8.4.3', r'lib\tkinter\tix8.4.3')]

build_exe_options = {
    'include_files': include_files,
}

bdist_msi_options = {}

setup(
    name='Demo',
    version='0.1',
    options = {
        'build_exe': build_exe_options,
        'bdist_msi': bdist_msi_options,
    },
    executables=[Executable('tix-demo.py', base='Win32GUI')],
)

然后通过执行以下命令构建 MSI:

python3 setup.py bdist_msi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    相关资源
    最近更新 更多