簡體   English   中英

PyInstaller exe 在 Tkinter 腳本上返回錯誤

[英]PyInstaller exe returning error on a Tkinter script

我正在嘗試通過 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

此處的未解決問題中建議了此解決方案

這是我的回答,我認為這會對您有所幫助:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM