TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
10.85k stars 1.02k forks source link

Pyinstaller's exe raises font error. #1310

Open mihaaairu opened 1 year ago

mihaaairu commented 1 year ago

To avoid json crashes and compile the program into one file, i putted necessary json into the .py file. And all worked nice, except font issue, which appeared unpredictable. I've already made some builds with json import as .py file with dictionary, and all worked well. So, i'm not sure, that json causes that. So, now about the main issue. After pyinstaller --one-file main.pyw, created .exe file raises this error:

Traceback (most recent call last):
  File "main.pyw", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\__init__.py", line 10, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\windows\__init__.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\windows\ctk_tk.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\windows\widgets\__init__.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\windows\widgets\ctk_button.py", line 8, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\windows\widgets\core_widget_classes\__init__.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\windows\widgets\core_widget_classes\dropdown_menu.py", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "customtkinter\windows\widgets\font\__init__.py", line 21, in <module>
AttributeError: 'NoneType' object has no attribute 'write'

I don't understand the problem, as long as i didn't use any custom_tkinter fonts and imported CTkTextbox only.

mihaaairu commented 1 year ago

Looks like I figured out the main problem. I've used CTk text widget with 'font' option, which calls font package. And pyinstaller can't attach this package (font files) to the .exe, IMHO. I'm not sure about real reason which cause crash. So, it need to be tested.

Rc1998 commented 11 months ago

I am also having this issue, no matter how many ways I include the customtkinter files, even on minimal programs (ie: importing customtkinter and showing a single label). The program works fine running directly with python, but when it is packaged up I get the same error. Seems to only be an issue with windows, as I am not having the issue on WSL Debian

Anonymous6598 commented 11 months ago

In my opinion, you should try auto-py-to-exe. It's better than pyinstaller because of better gui and functionality. You might have forgotten to add some binaries or something else. I also use customtkinter framework with auto-py-to-exe and trust me, there is nothing better than that thing. here is instruction of how to use it: https://customtkinter.tomschimansky.com/documentation/packaging

KaneDM commented 4 months ago

Having the same issue.

From what I can tell, the actual problem is not that CTK fails to load the fonts, but that CTK tries to write to the console explaining the failure. Because .pyw files have no console to write to, it crashes. If CTK's font management functions didn't have those write() commands, my EXE would run.

In the meantime, I've just created the EXE from a .py file so there's a console to push the error to.