gpt4 book ai didi

python - PyInstaller exe 在 Tkinter 脚本上返回错误

转载 作者:行者123 更新时间:2023-12-02 09:48:30 26 4
gpt4 key购买 nike

我正在尝试通过 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()

最佳答案

这似乎是在 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 中建议的。

关于python - PyInstaller exe 在 Tkinter 脚本上返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56503113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com