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

一世执手 提交于 2020-01-06 14:12:27

问题


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.


回答1:


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.




回答2:


The following works for me:

import wxversion
wxversion.select('3.0')
import wx



回答3:


Following has worked for me:

import wxversion
wxversion.select('3.0')
import wx

PS When you use python env, you may see a tip "select xxx".



来源:https://stackoverflow.com/questions/21551424/attributeerror-module-object-has-no-attribute-pyscrolledwindow-in-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!