can't run py app after compile to exe by py2exe , gettext

U

ulysses

hi.

I use python 23,py2exe 0.4.3 ,wxpython do my py app in win32.
I use gettext to support multi languages. I build a small fuction for load
language at top of main module.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def setLan(lan):
import gettext
langs = gettext.GNUTranslations(open (join ( localPath,
( "lan/"+lan+".mo" ) )
) )
langs.install()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Above run normally in debug mode, when I compile to exe by py2exe.
the exe can't run, no error raised, I can see exe in task manager.
but after few seconds , exe disappear automaticlly.

If I remove the function setLan, EXE can show main GUI.
But the function I has used it in another app,python22 ,wxpython.

So I use other way of show multi language.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def setLan():
t = gettext.translation("tbt", os.path.join(dir,"locale\\"),
languages=['en'])
t.install()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

situation same as before, can run in script mode, exe can't show.
Remove this function, program ok.

I don't what happen , I have test many many times.
Somebody help me :(

ulysses
 
U

ulysses

I do a small test app for this. Still can't run.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env python
#Boa:App:BoaApp

from wxPython.wx import *

def setLan():
import gettext
lan=gettext.GNUTranslations(open('en.mo'))
lan.install()

class BoaApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
setLan()
self.main = wxFrame1(None)
# needed when running from Boa under Windows 9X
self.SetTopWindow(self.main)
self.main.Show();self.main.Hide();self.main.Show()
return True

class wxFrame1(wxFrame):
def __init__(self, parent):
wxFrame.__init__(self, id=-1, name='', parent=parent,
pos=wxPoint(193, 111), size=wxSize(505, 223),
style=wxDEFAULT_FRAME_STYLE, title='wxFrame1')
self.SetClientSize(wxSize(497, 196))
self.SetBackgroundColour(wxColour(192, 192, 192))
self.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL, False, 'Tahoma'))

self.staticText2 = wxStaticText(id=2222,
label=_('help me'), name='staticText2', parent=self, pos=wxPoint(72,
128), size=wxSize(336, 40), style=0)

self.staticText1 = wxStaticText(id=3333,
label=_('show text'), name='staticText1', parent=self,
pos=wxPoint(72, 56), size=wxSize(320, 48), style=0)

def main():
application = BoaApp(0)
application.MainLoop()

if __name__ == '__main__':
main()

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
full source package
please download from

http://211.90.187.42/ourbt/gettexttest.rar

you test in in your computer. Thanks.

Ulysses
 
T

Thomas Heller

I do a small test app for this. Still can't run.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
full source package
please download from

http://211.90.187.42/ourbt/gettexttest.rar

you test in in your computer. Thanks.

I tried it, and it seems you have to make sure that the en.mo file is in
the same directory as the exe, and you have to manually include the
'encodings' package - there's a command line switch for that.

To help to find these types of problems, it's always useful to build the
exe as a console version first with the --console command line flag to
py2exe. There's no way for the --windows exe to notify you of the
tracebacks.

And if you want to try the 0.5.0 version of py2exe (which requires
Python 2.3), here is the setup script you would use:

"""
from distutils.core import setup
import py2exe

setup(name='testgettext',
options = {"py2exe": {"packages": ["encodings"]}},
windows = ['main.py'],
data_files = [("", ["en.mo"])],
)
"""

The latest py2exe 0.5.0 creates windows programs in such a way that
tracebacks are routed into a log file (that would be 'main.exe.log' in
the above case), and even displayes a message box when the program ends
pointing the user to the logfile.

Thomas
 
U

ulysses

Thank you very much.

I was killed this question. completely remove python22 and
python23,wxpython,py2exe. then reinstall python22,wxpython,py2exe
0.4.1.

Rewrite my source code to a new py file. it's work.
I still don't know where is bug. But I solve it.
maybe my code very confusion. Python don't like awful code. :)

anyway ,thanks Heller.

I do a small test app for this. Still can't run.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
full source package
please download from

http://211.90.187.42/ourbt/gettexttest.rar

you test in in your computer. Thanks.

I tried it, and it seems you have to make sure that the en.mo file is in
the same directory as the exe, and you have to manually include the
'encodings' package - there's a command line switch for that.

To help to find these types of problems, it's always useful to build the
exe as a console version first with the --console command line flag to
py2exe. There's no way for the --windows exe to notify you of the
tracebacks.

And if you want to try the 0.5.0 version of py2exe (which requires
Python 2.3), here is the setup script you would use:

"""
from distutils.core import setup
import py2exe

setup(name='testgettext',
options = {"py2exe": {"packages": ["encodings"]}},
windows = ['main.py'],
data_files = [("", ["en.mo"])],
)
"""

The latest py2exe 0.5.0 creates windows programs in such a way that
tracebacks are routed into a log file (that would be 'main.exe.log' in
the above case), and even displayes a message box when the program ends
pointing the user to the logfile.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top