PyInstaller exe возвращает ошибку в скрипте Tkinter - PullRequest
1 голос
/ 08 июня 2019

Я пытаюсь упаковать простой апплет, построенный с использованием стандартной библиотеки python, с графическим интерфейсом Tkinter через Pyinstaller для распространения. 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()

1 Ответ

1 голос
/ 08 июня 2019

Это, кажется, известная проблема для использования --onefile на OS X

Попробуйте это из каталога, где у вас есть скрипт Python

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

Это решение было предложено в открытом выпуске здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...