4

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 !!!

4
  • If you want help please share you code. It becomes ways easier to understand your issue. Commented May 17, 2022 at 18:58
  • 2
    Your code is looking for the file blue.json. If you wan to deploy the .exe that file must be included in it, otherwise you get the File not found error. Your bundled .exe knows to look for it in the temporary folder with _MEI in the name. But it isn't there because you did not specify it at build time. Read the documenation about creating a .spec file that will allow you to include needed resources in the .exe.
    – BoarGules
    Commented May 17, 2022 at 19:00
  • if you use files with data/resources then you have to manually add them to PyInstaller configuration (file .spec) because PyInstaller doesn't check what resources you use.You can also add it in command line --add-data "blue.json;.". You can find more details in PyInstaller documentation.
    – furas
    Commented May 17, 2022 at 19:37
  • Can you please elaborate a bit more furas. I am very new to Python exe making and cant quite get it. Just to tell you the file i am trying to convert to exe is named as try45.py. So can you please write the complete command i have to give in command console Commented May 18, 2022 at 5:50

4 Answers 4

6

had the same problem, adding custom tkinter folder data in site-packages folder into console command solved it, here:

pyinstaller --noconfirm --onefile --windowed --add-data "C:\Users\(your pc name)\AppData\Local\Programs\Python\(your python version that has custom tkinter)\Lib\site-packages\customtkinter;customtkinter/"  "<Path to Python Script>"
1
  • Since you're adding data from our local computer. Will the shared .exe compile and run without the directory defined in the --add-data flag in the target user's PC?
    – hkh
    Commented Jan 6, 2023 at 10:00
2

On your terminal navigate to your directory that contains your GUI using cd<path> Then use this exact command to get your .exe

pyinstaller -F BooyooToDo.py --collect-all customtkinter -w

1
0

I had the same issue. Have tried many different solutions, including the one suggested by "noor osama", which did not work for me. What eventually worked for me was the following code:

conda activate <env>
cd <location of .py file>
pyinstaller -F <.py file> --collect-all customtkinter

Hope this works for you too!

0

I tried "noor osama" solution, but got a problem: pypaperclip(ModuleNotFoundError: No module named 'pyperclip')

So I tried using "auto-py-to-exe" and added the package "pyperclip" in "--hidden-import" under the "Advance" option.

Not the answer you're looking for? Browse other questions tagged or ask your own question.