Cx_freeze converted executable is not working for ttkbootstrap scripts
Question:
After converting my ttkbootstrap
project file into exe
by using cx_freeze
.
When I run the executable
file. I get this error and my program
does not execute.
File "C:UsersKANWARAppDataLocalProgramsPythonPython310Libsite-packagescx_Freezeinitscripts__startup__.py", line 120, in run
module_init.run(name + "__main__")
File "C:UsersKANWARAppDataLocalProgramsPythonPython310Libsite-packagescx_FreezeinitscriptsConsole.py", line 16, in run
exec(code, module_main.__dict__)
File "main.py", line 207, in <module>
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstrapwindow.py", line 273, in __init__
self._style = Style(themename)
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstrapstyle.py", line 488, in __init__
localization.initialize_localities()
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstraplocalizationmsgs.py", line 9, in initialize_localities
m.initialize()
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstraplocalizationmsgs.py", line 27, in initialize
MessageCatalog.set_many(self.locale, *messages)
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstraplocalizationmsgcat.py", line 142, in set_many
return int(root.tk.eval(out))
_tkinter.TclError: invalid command name "::msgcat::mcmset"
In my script
I had included following library files.
from ttkbootstrap import *
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs.dialogs import Messagebox
I’m facing this issue everytime. Please is there any solution for this.
Here’s my setup.py
from cx_Freeze import setup, Executable
import sys
base = None
if (sys.platform == "win32"):
base = "Win32GUI" # Tells the build script to hide the console.
setup(name = "e_mail",
version = "0.1",
description = 'PURF BY KANWAR ADNAN',
executables = [Executable(r"main.py")]
)
Answers:
Below is not a real solution.
Only first aid.
In your environment’s Bootstrap folder (site-packagesttkbootstraplocalization),
Please rewrite msgcat.py as follows.
from ttkbootstrap.window import get_default_root
class MessageCatalog:
@staticmethod
def translate(src):
return src
@staticmethod
def locale(newlocale=None):
return newlocale
@staticmethod
def preferences():
return []
@staticmethod
def load(dirname):
return 0
@staticmethod
def set(locale, src, translated=None):
pass
@staticmethod
def set_many(locale, *args):
return 1
@staticmethod
def max(*src):
return 1
This operation has the side effect of disabling the ability to switch languages.
Well, I just installed auto-py-to-exe
and converted my script
into exe
without any problems.
Also, I used the virtual environment term. I installed virtualenv
and made a virtual environment and that helped me reducing 450+ MBs
of size my application.
Because auto-py-to-exe
includes almost all the libraries in the python lib
.
After converting my ttkbootstrap
project file into exe
by using cx_freeze
.
When I run the executable
file. I get this error and my program
does not execute.
File "C:UsersKANWARAppDataLocalProgramsPythonPython310Libsite-packagescx_Freezeinitscripts__startup__.py", line 120, in run
module_init.run(name + "__main__")
File "C:UsersKANWARAppDataLocalProgramsPythonPython310Libsite-packagescx_FreezeinitscriptsConsole.py", line 16, in run
exec(code, module_main.__dict__)
File "main.py", line 207, in <module>
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstrapwindow.py", line 273, in __init__
self._style = Style(themename)
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstrapstyle.py", line 488, in __init__
localization.initialize_localities()
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstraplocalizationmsgs.py", line 9, in initialize_localities
m.initialize()
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstraplocalizationmsgs.py", line 27, in initialize
MessageCatalog.set_many(self.locale, *messages)
File "C:UsersKANWARAppDataLocalProgramsPythonPython310libsite-packagesttkbootstraplocalizationmsgcat.py", line 142, in set_many
return int(root.tk.eval(out))
_tkinter.TclError: invalid command name "::msgcat::mcmset"
In my script
I had included following library files.
from ttkbootstrap import *
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs.dialogs import Messagebox
I’m facing this issue everytime. Please is there any solution for this.
Here’s my setup.py
from cx_Freeze import setup, Executable
import sys
base = None
if (sys.platform == "win32"):
base = "Win32GUI" # Tells the build script to hide the console.
setup(name = "e_mail",
version = "0.1",
description = 'PURF BY KANWAR ADNAN',
executables = [Executable(r"main.py")]
)
Below is not a real solution.
Only first aid.
In your environment’s Bootstrap folder (site-packagesttkbootstraplocalization),
Please rewrite msgcat.py as follows.
from ttkbootstrap.window import get_default_root
class MessageCatalog:
@staticmethod
def translate(src):
return src
@staticmethod
def locale(newlocale=None):
return newlocale
@staticmethod
def preferences():
return []
@staticmethod
def load(dirname):
return 0
@staticmethod
def set(locale, src, translated=None):
pass
@staticmethod
def set_many(locale, *args):
return 1
@staticmethod
def max(*src):
return 1
This operation has the side effect of disabling the ability to switch languages.
Well, I just installed auto-py-to-exe
and converted my script
into exe
without any problems.
Also, I used the virtual environment term. I installed virtualenv
and made a virtual environment and that helped me reducing 450+ MBs
of size my application.
Because auto-py-to-exe
includes almost all the libraries in the python lib
.