Help Needed: AttributeError: module 'wx' has no attribute 'App'

Hey everyone,

I’m relatively new to wxPython and have been trying to get a simple app up and running. However, I keep running into this error:

AttributeError: module 'wx' has no attribute 'App'

Here’s a snippet of my code:

import wx

class MyApp(wx.App):
    def OnInit(self):
        frame = wx.Frame(None, -1, 'Hello wxPython')
        frame.Show(True)
        return True

app = wx.App(False)
app.MainLoop()

I’m not sure what’s going wrong here. When I was searching about this, I came across to these resources/articles AttributeError: module 'wx' has no attribute 'App' mulesoft interview questions python - Error with wxPython - partially initialized module 'wx' has no attribute 'Frame' (most likely due to a circular import) - Stack Overflow as per them I have double-checked my wxPython installation and it seems to be fine. I’m running Python 3.8 on Windows 10, and I’ve installed wxPython using pip install wxPython.

Has anyone encountered this issue before or know what might be causing it? Any help or suggestions would be greatly appreciated!

Thanks in advance!

Best Regards

Do you have a file called wx.py in the local directory? If so, python will import that file instead of the real wxPython module.

Another point (unrelated to the error you are getting) - in your sample code you define the class MyApp but you don’t use it.

some interesting loader attributes (if you lost your way) :wink:

import wx

print(wx.App.__module__)
print(wx.__spec__)
print(wx.__path__)
print(wx.__file__)