help me. py2exe problem.

Hi, I have one question.

I made Executable by using py2exe.
but, It display error message such as "Subclass 'FINM.MyFrame' not
found for resource 'MainFrame', not subclassing!."

It works fine before making exe.
I have not been able to make it work.

code here:
# -*- coding: utf-8 -*-

xrc_str = """<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
    <object class="wxFrame" name="MainFrame" subclass="FINM.MyFrame">
        <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
        <title></title>
    </object>
</resource>"""

import wx
from wx import xrc

···

#===============================================================================
# Global
#===============================================================================
_firstEventType = wx.EVT_WINDOW_CREATE

#===============================================================================
# MyFrame
#===============================================================================
class MyFrame( wx.Frame ):
    def __init__( self ): #IGNORE:W0231
        pre = wx.PreFrame()
        self.PostCreate( pre )
        self.Bind( _firstEventType , self.OnCreate )

    def OnCreate( self , event ):#IGNORE:W0613
        self.Unbind( _firstEventType )

#===============================================================================
# FINM
#===============================================================================
class FINM( wx.App ):
    def __init__( self ):
        wx.App.__init__( self , False )

    def OnInit( self ):
        xmlRes = xrc.EmptyXmlResource()
        xmlRes.LoadFromString( xrc_str )
        assert( xmlRes )

        self.frame = xmlRes.LoadFrame( None , 'MainFrame' )
#IGNORE:W0201
        assert( self.frame )

        self.frame.SetSize( ( 1024, 768 ) )
        self.frame.Center()
        self.frame.Show()

        return True

def main():
    app = FINM()
    app.MainLoop()

if __name__ == '__main__':
    main()

P.S
Sorry about my poor english

Oh, I missed one thing.

setup.py code here:

# setup.py
from distutils.core import setup
import py2exe

setup( windows = ["FINM.py"], )

···

On 9월1일, 오후4시02분, Cookie <newercoo...@gmail.com> wrote:

Hi, I have one question.

I made Executable by using py2exe.
but, It display error message such as "Subclass 'FINM.MyFrame' not
found for resource 'MainFrame', not subclassing!."

It works fine before making exe.
I have not been able to make it work.

code here:
# -*- coding: utf-8 -*-

xrc_str = """<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc&quot; version="2.3.0.1">
    <object class="wxFrame" name="MainFrame" subclass="FINM.MyFrame">
        <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
        <title></title>
    </object>
</resource>"""

import wx
from wx import xrc

#===============================================================================
# Global
#===============================================================================
_firstEventType = wx.EVT_WINDOW_CREATE

#===============================================================================
# MyFrame
#===============================================================================
class MyFrame( wx.Frame ):
    def __init__( self ): #IGNORE:W0231
        pre = wx.PreFrame()
        self.PostCreate( pre )
        self.Bind( _firstEventType , self.OnCreate )

    def OnCreate( self , event ):#IGNORE:W0613
        self.Unbind( _firstEventType )

#===============================================================================
# FINM
#===============================================================================
class FINM( wx.App ):
    def __init__( self ):
        wx.App.__init__( self , False )

    def OnInit( self ):
        xmlRes = xrc.EmptyXmlResource()
        xmlRes.LoadFromString( xrc_str )
        assert( xmlRes )

        self.frame = xmlRes.LoadFrame( None , 'MainFrame' )
#IGNORE:W0201
        assert( self.frame )

        self.frame.SetSize( ( 1024, 768 ) )
        self.frame.Center()
        self.frame.Show()

        return True

def main():
    app = FINM()
    app.MainLoop()

if __name__ == '__main__':
    main()

P.S
Sorry about my poor english

Cookie wrote:

Oh, I missed one thing.

setup.py code here:

# setup.py
from distutils.core import setup
import py2exe

setup( windows = ["FINM.py"], )

Hi, I have one question.

I made Executable by using py2exe.
but, It display error message such as "Subclass 'FINM.MyFrame' not
found for resource 'MainFrame', not subclassing!."

It works fine before making exe.
I have not been able to make it work.

code here:
# -*- coding: utf-8 -*-

xrc_str = """<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc&quot; version="2.3.0.1">
    <object class="wxFrame" name="MainFrame" subclass="FINM.MyFrame">
        <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
        <title></title>
    </object>
</resource>"""

import wx
from wx import xrc

#===============================================================================
# Global
#===============================================================================
_firstEventType = wx.EVT_WINDOW_CREATE

#===============================================================================
# MyFrame
#===============================================================================
class MyFrame( wx.Frame ):
    def __init__( self ): #IGNORE:W0231
        pre = wx.PreFrame()
        self.PostCreate( pre )
        self.Bind( _firstEventType , self.OnCreate )

    def OnCreate( self , event ):#IGNORE:W0613
        self.Unbind( _firstEventType )

#===============================================================================
# FINM
#===============================================================================
class FINM( wx.App ):
    def __init__( self ):
        wx.App.__init__( self , False )

    def OnInit( self ):
        xmlRes = xrc.EmptyXmlResource()
        xmlRes.LoadFromString( xrc_str )
        assert( xmlRes )

        self.frame = xmlRes.LoadFrame( None , 'MainFrame' )
#IGNORE:W0201
        assert( self.frame )

        self.frame.SetSize( ( 1024, 768 ) )
        self.frame.Center()
        self.frame.Show()

        return True

def main():
    app = FINM()
    app.MainLoop()

if __name__ == '__main__':
    main()

P.S
Sorry about my poor english
    

I haven't used xrc, but I believe that py2exe does not handle the xrc
definition files automatically, you have to tell it to include them
using data_files option. See on the following wiki page for more detail,
there this option is used to include MS dll files.

http://wiki.wxpython.org/py2exe

Werner

···

On 9월1일, 오후4시02분, Cookie <newercoo...@gmail.com> wrote:

Hi, Werner.

I don't use xrc definition file separately.
xrc is nested in my code.

···

On 9월1일, 오후4시24분, werner <wbru...@free.fr> wrote:

Cookie wrote:
> Oh, I missed one thing.

> setup.py code here:

> # setup.py
> from distutils.core import setup
> import py2exe

> setup( windows = ["FINM.py"], )

> On 9월1일, 오후4시02분, Cookie <newercoo...@gmail.com> wrote:

>> Hi, I have one question.

>> I made Executable by using py2exe.
>> but, It display error message such as "Subclass 'FINM.MyFrame' not
>> found for resource 'MainFrame', not subclassing!."

>> It works fine before making exe.
>> I have not been able to make it work.

>> code here:
>> # -*- coding: utf-8 -*-

>> xrc_str = """<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
>> <resource xmlns="http://www.wxwindows.org/wxxrc&quot; version="2.3.0.1">
>> <object class="wxFrame" name="MainFrame" subclass="FINM.MyFrame">
>> <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
>> <title></title>
>> </object>
>> </resource>"""

>> import wx
>> from wx import xrc

>> #===============================================================================
>> # Global
>> #===============================================================================
>> _firstEventType = wx.EVT_WINDOW_CREATE

>> #===============================================================================
>> # MyFrame
>> #===============================================================================
>> class MyFrame( wx.Frame ):
>> def __init__( self ): #IGNORE:W0231
>> pre = wx.PreFrame()
>> self.PostCreate( pre )
>> self.Bind( _firstEventType , self.OnCreate )

>> def OnCreate( self , event ):#IGNORE:W0613
>> self.Unbind( _firstEventType )

>> #===============================================================================
>> # FINM
>> #===============================================================================
>> class FINM( wx.App ):
>> def __init__( self ):
>> wx.App.__init__( self , False )

>> def OnInit( self ):
>> xmlRes = xrc.EmptyXmlResource()
>> xmlRes.LoadFromString( xrc_str )
>> assert( xmlRes )

>> self.frame = xmlRes.LoadFrame( None , 'MainFrame' )
>> #IGNORE:W0201
>> assert( self.frame )

>> self.frame.SetSize( ( 1024, 768 ) )
>> self.frame.Center()
>> self.frame.Show()

>> return True

>> def main():
>> app = FINM()
>> app.MainLoop()

>> if __name__ == '__main__':
>> main()

>> P.S
>> Sorry about my poor english

I haven't used xrc, but I believe that py2exe does not handle the xrc
definition files automatically, you have to tell it to include them
using data_files option. See on the following wiki page for more detail,
there this option is used to include MS dll files.

py2exe - wxPyWiki

Werner

Cookie wrote:

Hi, Werner.

I don't use xrc definition file separately.
xrc is nested in my code.
  

In that case can you create a smallish runnable example.

Werner

I think he did provide such an example - as long as you save the code
provided as FINM.py.
The problem may be that the subclass must be in a loadable python
module - in your case, this is the same as the main script. However,
py2exe does not seem to preserve the main module (look in the
'library.zip' file to see what is included) as an actual loadable
module, so xmlRes.LoadFrame can't find the proper subclass.

A quick (untested) solution would be to write a script 'runFINM.py'
with the following:
import FINM
if __name__=="__main__":
  FINM.main()

and change the setup.py file:
setup( windows = ["runFINM.py"], )

For larger projects, you'll probably break things up into modules
anyway, which has worked well with py2exe, in my experience.

-matt

···

On Sep 1, 4:10 am, werner <wbru...@free.fr> wrote:

Cookie wrote:
> Hi, Werner.

> I don't use xrc definition file separately.
> xrc is nested in my code.

In that case can you create a smallish runnable example.

Cookie wrote:

Hi, I have one question.

I made Executable by using py2exe.
but, It display error message such as "Subclass 'FINM.MyFrame' not
found for resource 'MainFrame', not subclassing!."

It works fine before making exe.
I have not been able to make it work.

code here:
# -*- coding: utf-8 -*-

xrc_str = """<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc&quot; version="2.3.0.1">
    <object class="wxFrame" name="MainFrame" subclass="FINM.MyFrame">
        <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
        <title></title>
    </object>
</resource>"""

XRC subclassing works by doing a dynamic import of the module named in the subclass attribute. When you run py2exe with FINM as the main module then I don't think it is importable as "FINM" any more. Try moving that class to another module and change the name in the subclass attribute to match. You'll also need to tell py2exe to include that module since there isn't an explicit import for it in the Python code that py2exe will be scanning.

···

--
Robin Dunn
Software Craftsman

Hi, Matteo, Robin Dunn.
It works fine.
very thanks!

···

On 9월2일, 오전1시49분, Robin Dunn <ro...@alldunn.com> wrote:

Cookie wrote:
> Hi, I have one question.

> I made Executable by using py2exe.
> but, It display error message such as "Subclass 'FINM.MyFrame' not
> found for resource 'MainFrame', not subclassing!."

> It works fine before making exe.
> I have not been able to make it work.

> code here:
> # -*- coding: utf-8 -*-

> xrc_str = """<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
> <resource xmlns="http://www.wxwindows.org/wxxrc&quot; version="2.3.0.1">
> <object class="wxFrame" name="MainFrame" subclass="FINM.MyFrame">
> <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
> <title></title>
> </object>
> </resource>"""

XRC subclassing works by doing a dynamic import of the module named in
the subclass attribute. When you run py2exe with FINM as the main
module then I don't think it is importable as "FINM" any more. Try
moving that class to another module and change the name in the subclass
attribute to match. You'll also need to tell py2exe to include that
module since there isn't an explicit import for it in the Python code
that py2exe will be scanning.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org