【问题标题】:PyInstaller exe returning error on a Tkinter scriptPyInstaller exe 在 Tkinter 脚本上返回错误
【发布时间】:2019-10-23 11:31:24
【问题描述】:

我正在尝试通过 Pyinstaller 将使用标准 python 库构建的简单小程序与 Tkinter GUI 打包以进行分发。 PyInstaller 编译(正确的术语?)很好,但是当我打开 exe 时,我得到以下信息:

Traceback (most recent call last):
  File "site-packages/PyInstaller/loader/rthooks/pyi_rth__tkinter.py", line 28, in <module>
FileNotFoundError: Tcl data directory "/var/folders/sj/r0yyz8393ld2xrd_wf65bwxr0000gn/T/_MEIDeFnFy/tcl" not found.
[67821] Failed to execute script pyi_rth__tkinter
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

我尝试调整我的编译设置,例如添加 --hidden-import tkinter 无济于事。

这是脚本:

import math
import tkinter as tk
from tkinter import simpledialog as sd

grades = []

def convert(grades):
    #long function here

def get_num_classes():
    while True:
        try:
            global num_classes
            num_classes =  sd.askinteger("number of classes", "Number of classes: ")
            return num_classes
        except ValueError:
            print('Try again')

def get_current():
    global current_gpa
    current_gpa = sd.askfloat("current gpa", "Current GPA: ")
    return current_gpa

def grade_append():
    y = 0
    while y < num_classes:
        grade = sd.askstring("grade", "Letter Grade: ")
        grade = grade.upper()
        grades.append(grade)
        y = y+1

def calculate(grade_points, current_gpa, classes):
    global cum_gpa
    gpa = grade_points / classes
    cum_gpa = (gpa + current_gpa) / 2
    return cum_gpa

root = tk.Tk()
root.title("GPA Calculator")
root.geometry("225x50")

get_num_classes()

get_current()

grade_append()

total_points = convert(grades)

calculate(total_points, current_gpa, num_classes)
cum_gpa = round(cum_gpa, 2)

print(cum_gpa)
print(grades)

w = tk.Label(root, text="Your new cumulative GPA is %s" % (cum_gpa))
w.pack()

tk.mainloop()

【问题讨论】:

  • pyinstaller 的版本是多少?你用什么命令来打包?你在哪里运行 exe?
  • @DavidSidarous 1. 3.4 2. pyinstaller --onefile --hidden-import tkinter 我在上面说过。 3.在默认的dist文件夹中打包到项目主文件夹中。
  • tkinter 更新到最新版本了吗?
  • @DavidSidarous 应该是,我在过去两周内安装的。
  • 再检查一下,您是否打包在与目标环境相同的操作系统中?这似乎是 OS X?

标签: python tkinter pyinstaller


【解决方案1】:

这似乎是在 OS X 上使用 --onefile 的一个已知问题

从你有 python 脚本的目录试试这个

pyinstaller --onefile --add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk' --add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' your_script.py

这个解决方案是在公开问题here中提出的

【讨论】:

    【解决方案2】:

    这是我的回答,我认为这会对你有所帮助:

    pyinstaller --onefile --add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk' --add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' your_script.py

    或者没有控制台代码是:

    pyinstaller --onefile --noconsole --add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk' --add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' your_script.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-27
      • 2023-03-15
      • 2018-12-09
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 2018-09-12
      相关资源
      最近更新 更多