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.

3

There are 3 best solutions below

1
On BEST ANSWER

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.

0
On

I had the same problem as you and this is my solution. I think it's more like a tricks

  1. Find your Python Directory where you save it in your computer

my case: C:\Users\PC-Name\AppData\Local\Programs\Python\Python310

  1. Go to Folder tcl -> tk8.6 and put your custom .tcl file here (Ex: sprites_light.tcl)
  2. Execute your programs by pyinstaller Main.exe
  3. When Done, Go to your Program Folder. There is a new folder created. Go dist -> <your-exe-file-name> -> tk And find your tcl file . If it's there then you've made it
  4. Finally, because it will need some *.png files to run well, so you will also copy the folder containing the png to the above folder (inside tk folder)

Goodluck, I hope it helpful!!

1
On

This worked for me and I thought share it here for all who needs it:

To convert Python to Windows

import os
import sys

def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS # after running the pyinstaller, if still looking
        # for temp folder then use sys._MEIPASS2 and if needed \\ instead of / for
        # all the path directories
    except Exception:
        base_path = os.path.abspath(".")

return os.path.join(base_path, relative_path)

Replace the "img/file_names" with resource_path("img/file_names")

in the Terminal type: pyinstaller.exe --onefile --windowed --icon=your_image.ico Your_File.py

or in windows CMD type: pyinstaller --onefile --windowed --icon=your_image.ico Your_File.py

The executable file will be available in a new folder called "dist".

now copy all the dependent folders into the "dist" folder

run the .exe and if all fine then zip the folder to share.

Delete Build and Dist folder along with any .spec files.

Replace the resource_path("img/file_names") back to "img/file_names"

Use "inno setup" software to create a proper setup file, use this link towards the end of the video: https://www.youtube.com/watch?v=p3tSLatmGvU

If file not found error: Use MEIPASS instead of MEIPASS2 or vise versa and then \ instead of / if needed.