Reputation: 65
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.
Upvotes: 1
Views: 1159
Reputation: 21
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.
Upvotes: 0
Reputation: 46669
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.
Upvotes: 2
Reputation: 63
I had the same problem as you and this is my solution. I think it's more like a tricks
my case: C:\Users\PC-Name\AppData\Local\Programs\Python\Python310
tcl
-> tk8.6
and put your custom .tcl file here (Ex: sprites_light.tcl)pyinstaller Main.exe
dist
-> <your-exe-file-name>
-> tk
And find your tcl file . If it's there then you've made itGoodluck, I hope it helpful!!
Upvotes: 0