[Python.NET] CLR + wxPython + OLE initialization

Brian Almond pythonista at sbcglobal.net
Fri Apr 9 22:33:43 EDT 2004

Today I found that in my wxPython apps, adding a CLR
import at the top of the files causes wxPython's
mainloop to generate a warning message box which reads
"Could not initialize OLE".  Otherwise, the
application seemed functional.  I experimented with
it, and it seems that delaying CLR-related imports
until after the wx Mainloop has started does the

Here's a tiny wxPython app that demonstrates the

import wx
#import CLR

class MyApp(wx.App):
    def OnInit(self):
#        global CLR
#        import CLR
        self.frame = wx.Frame(None, -1, 'Test Window')
        return True

app = MyApp(0)

If you uncomment the first comment, the application
window will open, and an OleInitialize failure message
will pop up.  If you instead uncomment the second two
comments, the application window will open without
error. (Note: this was with the latest wxPython build, - I assume similar failures occur with older

It's not a big deal to move the imports, but it's a
little unnatural to me.  Is this something that's
broken in Python for .NET, or .NET, or...  Here's a
possibly related message I found on wx-users: http://lists.wxwidgets.org/archive/wx-users/msg30069.html

More information about the PythonDotNet mailing list