Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyInstaller exe returning error on a Tkinter script

I'm trying to package a simple applet built using the standard python library with a Tkinter GUI through Pyinstaller for distribution. PyInstaller compiles (correct term?) it fine, but when I open the exe, I get the following:

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]

I've tried tweaking my compile settings such as adding --hidden-import tkinter to no avail.

Here's the script:

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()
like image 637
John Allison Avatar asked Jun 08 '19 03:06

John Allison


People also ask

Does TkInter work with PyInstaller?

PyInstaller works out of the box with Tkinter and as of writing, current versions of PyInstaller are compatible with Python 3.6+. Whatever project you're working on, you should be able to package your apps. You can install PyInstaller using pip .

Why is PyInstaller not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

Does PyInstaller work with packages?

If your script imports a module from an “egg”, PyInstaller adds the egg and its dependencies to the set of needed files. PyInstaller also knows about many major Python packages, including the GUI packages Qt (imported via PyQt or PySide), WxPython, TkInter, matplotlib, and other major packages.

Does PyInstaller package Python?

PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules.


2 Answers

This seems to be a known problem for using --onefile on OS X

Try this from the directory where you have the python script

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

This solution was suggested in the open issue here

like image 198
David Sidarous Avatar answered Oct 04 '22 12:10

David Sidarous


This is my answer I think that this will help you :

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

or for no console code is :

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

like image 44
Pythonic Persons Avatar answered Oct 04 '22 12:10

Pythonic Persons