Search code examples
pythontkinterexettkthonny

_tkinter.TclError: couldn't read file "C:\Users\{username}\AppData\Local\Temp\_MEI45522\sv_ttk\sv.tcl": no such file or directory


I have used Sun Valley Ttk Theme for my project (.py). It works on IDE (Thonny) but doesn't work when I converted the .py file to .exe.

I got this error for the line: sv_ttk.set_theme("light"):

_tkinter.TclError: couldn't read file "C:\Users\{username}\AppData\Local\Temp\_MEI45522\sv_ttk\sv.tcl": no such file or directory.

Obviously this directory doesn't exist but why should it? What should I do?

Theme folder, .py and .exe are in the same directory.

Besides I used

-add-data 

to add theme folders as additional while converting to .exe.


Solution

  • You need to include sv_ttk module into the executable by using --collect-data option of PyInstaller:

    pyinstaller --onefile --collect-data sv_ttk project.py
    

    Assume project.py is the main python script.