'Problem in making an exe file using Pyinstaller (file made using tkinter and Custom tkinter)
I am trying to make a small application for data entry using tkinter and custom tkinter. The code runs fine in python and I made the exe file of it using pyinstaller --onefile --noconsole try45.py
But on running the exe file it gives error labelled as "Unhandled exception in script". Details of it are attached as below,
I have also attached the image of the error. The first two lines of it say "Failed to execute script 'try45' due to unhandled exception: [Errno 2] No such file or directory: 'C:\Users\Farzan Bashir\AppData\Local\Temp\_MEI127522\customtkinter\assets\themes\blue.json"
and the details in next lines are,
Traceback (most recent call last): File "try45.py", line 2, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter_init.py", line 3, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\widgets\customtkinter_input_dialog.py", line 4, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\widgets\customtkinter_label.py", line 4, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\widgets\customtkinter_tk.py", line 9, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\customtkinter_theme_manager.py", line 83, in File "customtkinter\customtkinter_theme_manager.py", line 16, in load_theme FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Farzan Bashir\AppData\Local\Temp\_MEI44122\customtkinter\assets\themes\blue.json'
PLEASE HELP !!!
Solution 1:[1]
This is a pyinstaller problem, read the customtkinter documentation:
https://github.com/TomSchimansky/CustomTkinter/wiki/Packaging#windows-pyinstaller-auto-py-to-exe
Solution 2:[2]
There are several issues in partition:
The call to
swapis passing values from your list, instead of indices.Even when the previous mistake is corrected, it will either move the pivot value to the
low+1index, or it will not move at all.The returned index
i, should be the one where the pivot was moved. In a correct implementation that meansiis the last index to which a value was moved, which was the value at indexhigh. This is not what is happening, as already with the first swap the pivot value is moved.The swap should be of the current value with the value at
i, so that all values up to the one at indexiare less or equal to the pivot value.
Here is the corrected partition function:
def partition(array, high, low):
pivot = array[high]
i = low - 1
for x in range(low, high+1):
if array[x] <= pivot:
i+=1
swap(array, x, i)
return i
These are the issues in the function g:
It is supposed to perform the sort in-place, so the
+operator for lists should not occur here, as that would create a new list. Moreover, the base case (inelse) does not return anything, so the+operator will fail with an errorpartition(array,high,low)is called twice, which is not only a waste, but the second call will in most cases return a different result, because the pivot can be different. This means the second call ofgwill potentially not work with an adjacent partition, but will either leave an (unsorted) gap, or work on an overlapping partition.
Here is a correction for the function g:
def g(array, low, high):
if low < high:
i = partition(array, high, low)
g(array, low, i-1)
g(array, i+1, high)
You should also consider using a better name than g, and change the order of the high/low parameters for partition: that reversed order is a good way to confuse the readers of your code.
Solution 3:[3]
Here is Hoare's quicksort algorithm implemented in Python -
def quicksort(A, lo, hi):
if lo >= 0 and hi >= 0 and lo < hi:
p = partition(A, lo, hi)
quicksort(A, lo, p)
quicksort(A, p + 1, hi)
def partition(A, lo, hi):
pivot = A[(hi + lo) // 2]
i = lo
j = hi
while True:
while A[i] < pivot:
i += 1
while A[j] > pivot:
j -= 1
if i >= j:
return j
swap(A, i, j)
def swap(A, i, j):
A[i], A[j] = A[j], A[i]
You can write g using lambda if you wish, but I would recommend to define an ordinary function instead -
g = lambda a: quicksort(a, 0, len(a) - 1)
Given a sample input, x -
x = [5,0,9,7,4,2,8,3,1,6]
g(x)
print(x)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
See this related Q&A if you would like to count the number of comparisons and swaps used.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tom |
| Solution 2 | trincot |
| Solution 3 | Mulan |
