Search code examples
pythonpython-2.7wxpython

AttributeError: 'module' object has no attribute 'PyScrolledWindow' in wxPython


My python version is 2.7 and wxPython ver 3.0 for python 32 bit 2.7 version. I was currently working on a GUI app with wxPython. I tested my code it was working fine, I paused my work saved my files. I started to install some software on my machine. Then when I again started to continue my work with wxPython suddenly I started to receive an error. The complete error is given below. I don't understand the reason. I didn't edit my code too. However I am able to execute my other python programmes.

Error:

File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\lib\scrolledpanel.py", line 21, in <module>
    class ScrolledPanel( wx.PyScrolledWindow ):
AttributeError: 'module' object has no attribute 'PyScrolledWindow'

I reinstalled wxPython but nothing changed. I tried to investigate using google. But all in vain. Can some provide me some advice on this?

The python code has following import statements:

import wx
import wx.lib.scrolledpanel

and I using the imports like this:

panel = wx.lib.scrolledpanel.ScrolledPanel(self, -1, size=(1000,500), pos=(0,50), style=wx.SIMPLE_BORDER)

Thanks for your time.


Solution

  • As per our chat: You have your project files located on Desktop. There are probably many more .py files on your desktop. Some of them shadow your imported library name, maybe something like wx.py. So instead of importing wx library, you import something else, what does not have needed contents.

    Try running your code in a more controlled environment, e.g. create a directory for your project, double check file names in that directory and your Python path for shadowing names. It should work.