【问题标题】:Tkinter python script converted to exe using pyinstaller on Windows 10 not working on Windows7在 Windows 10 上使用 pyinstaller 将 Tkinter python 脚本转换为 exe 在 Windows7 上不起作用
【发布时间】:2018-03-29 08:47:30
【问题描述】:

我最近在 Windows 10 操作系统上使用 tkinter 和 python 2.7 开发了一个基于 python 的 UI 脚本。为了将其分发给用户,我使用 pyinstaller 将脚本转换为单个文件 exe。 该脚本在所有 Windows 10 系统上都可以正常工作,但在 Windows 7 上会产生以下问题: “致命错误:无法运行...脚本” 我无法绕过它。 任何帮助表示赞赏。

提前谢谢..:)

【问题讨论】:

标签: python python-2.7 tkinter exe pyinstaller


【解决方案1】:

当您使用pyinstaller 将您的脚本编译为windows 10 中的executable 并希望在window 7 中使用它时,它将无法正常工作。

但是你可以用windows 7中的pyinstaller编译它并使用windows 7, 8, and 10中的可执行文件

还要注意这一点,在使用windows 7 32-bit 编译您的可执行文件并希望在windows 7 64-bit 操作系统版本中使用它时,请考虑操作系统的32-bit and 64-bit 版本,反之亦然。

因此,当您在 windows7 32-bit 版本中编译时,它将仅适用于 32-bit version of operating systems 而不适用于 64-bit version of windows operating system,反之亦然

【讨论】:

    【解决方案2】:

    也许您可以尝试使用 cx_Freeze 包在 Windows 中构建您的应用程序(注意:如果您的 PC 是 64 位,则应用程序将采用该架构,如果是 x86 或 32 位,则应用程序将采用 32 位)

    运行 cmd 并输入这个

    pip install cx_Freeze
    

    然后在同一目录中创建一个名为 setup.py 的文件并添加以下代码:

    import cx_Freeze
    import sys
    import os
    
    os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python27\\tcl\\tcl8.6" #you need to ubicate the library where tcl\tcl8.6 is
    os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python27\\tcl\\tk8.6" #you need to ubicate the library where tcl\tk8.6 is
    
    base = None
    
    if sys.platform == 'win32':
    base = "Win32GUI"
    
    executables = [cx_Freeze.Executable("name_of_your_app.py", base=base, icon="icon_of_your_app.ico")]
    
    cx_Freeze.setup(
    name = "Vtext",
    options = {"build_exe": {"packages":["tkinter"], "include_files":["icon_of_your_app.ico", "maybe_some_img_that_your_app_is_using.gif", "another_img.gif"]}},
    version = "1.0",
    description = "name_of_your_app",
    executables = executables
    )"""
    

    稍后打开一个 cmd 并更改您的应用所在的目录,例如:

    C:\Users\Myname> cd C:\Users\Myname\MyTkinterApp
    

    然后,输入:

    python setup.py build
    

    一切正常,您的应用程序即将构建

    观看此视频了解更多信息:https://www.youtube.com/watch?v=HosXxXE24hA&t=0s&index=29&list=PLQVvvaa0QuDclKx-QpC9wntnURXVJqLyk

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 2019-10-23
      • 2016-08-03
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 2020-12-05
      相关资源
      最近更新 更多