1 2 3 4 5 6 7 8 9 10 11 12 13 | import wx.App class MyApp(wx.App): def OnInit(self): wx.MessageBox('hello kelvin', 'wxApp') return True app = MyApp() app.mainloop() |
The seemingly correct code kept
throwing this error at me
>>>
Traceback (most recent call last):
File "C:\Python27\wx.py",
line 1, in
import wx.App
File "C:\Python27\wx.py",
line 1, in
import wx.App
ImportError: No module named App
>>>
I went on for minutes trying to
decipher where the bug was coming from only to notice that I saved the file
with wx.py (which obviously is the same name with the module i imported). Hence
what I had was my own module importing itself! :D
Moral of the story: avoid saving your
program with the name of a module to avoid running into troubles of conflicting
module names, rename your program and delete the already created python compiled
file(.pyc) if you’ve already made the mistake and rerun your program.
Thanks for reading!
0 comments:
Post a Comment