AttributeError: 'module' object has no attribute 'Frame' 解决方法
来源:互联网 发布:苹果6在线软件 编辑:程序博客网 时间:2024/06/14 20:57
最近对wxpython的GUI编程试用了下,试用过程中出现报错:
- Traceback (most recent call last):
- File "E:\study\python\wxpython1\stdout_err.py", line 7, in <module>
- class Frame(wx.Frame):
- AttributeError: 'module' object has no attribute 'Frame'
1、自己根本就没有安装wxpython,或者自己安装不正确,出现问题;自己import下wx测试即可;
2、自己命名的文件与python自带的模块文件名重名,这种情况只需将自己的文件改名即可。
3、如果以上都没有问题,还是出现一些异常报错,那就说明你可能安装了不止一个版本的wxpython,或者某个版本不准确;可用如下办法解决:
在文件开头加入import要使用的版本号
- import wxversion
- wxversion.select('2.8')
- import wx
对于版本号的确认可以参考自己的安装文件或py文件;
找到 C:\Python27\Lib\site-packages 目录下的wxversion.py文件
说明如下:
- #----------------------------------------------------------------------
- # Name: wxversion
- # Purpose: Allows a wxPython program to search for alternate
- # installations of the wxPython packages and modify sys.path
- # so they will be found when "import wx" is done.
- #
- # Author: Robin Dunn
- #
- # Created: 24-Sept-2004
- # RCS-ID: $Id: wxversion.py 49375 2007-10-23 21:41:52Z RD $
- # Copyright: (c) 2004 by Total Control Software
- # Licence: wxWindows license
- #----------------------------------------------------------------------
- """
- If you have more than one version of wxPython installed this module
- allows your application to choose which version of wxPython will be
- imported when it does 'import wx'. The main function of this module
- is `select` and you use it like this::
- import wxversion
- wxversion.select('2.4')
- import wx
- Or additional build options can also be selected, although they will
- not be required if they are not installed, like this::
- import wxversion
- wxversion.select('2.5.3-unicode')
- import wx
- Or you can require an exact match on the build options like this::
- import wxversion
- wxversion.select('2.5.3-unicode', optionsRequired=True)
- import wx
- Finally you can also specify a collection of versions that are allowed
- by your application, like this::
- import wxversion
- wxversion.select(['2.5.4', '2.5.5', '2.6'])
- import wx
- Of course the default wxPython version can also be controlled by
- setting PYTHONPATH or by editing the wx.pth path configuration file,
- but using wxversion will allow an application to manage the version
- selection itself rather than depend on the user to setup the
- environment correctly.
- It works by searching the sys.path for directories matching wx-* and
- then comparing them to what was passed to the select function. If a
- match is found then that path is inserted into sys.path.
- NOTE: If you are making a 'bundle' of your application with a tool
- like py2exe then you should *not* use the wxversion module since it
- looks at the filesystem for the directories on sys.path, it will fail
- in a bundled environment. Instead you should simply ensure that the
- version of wxPython that you want is found by default on the sys.path
- when making the bundled version by setting PYTHONPATH. Then that
- version will be included in your bundle and your app will work as
- expected. Py2exe and the others usually have a way to tell at runtime
- if they are running from a bundle or running raw, so you can check
- that and only use wxversion if needed. For example, for py2exe::
- if not hasattr(sys, 'frozen'):
- import wxversion
- wxversion.select('2.5')
- import wx
- More documentation on wxversion and multi-version installs can be
- found at: http://wiki.wxpython.org/index.cgi/MultiVersionInstalls
- """
希望对发现有同样问题的人有点帮助,这个问题之前就花了我很多时间一直没搞定,后来到公司的电脑比较了下才ok的。
- >>> print wx.version()
- 2.8.12.1 (msw-unicode)
这是我转载别人的 。http://blog.csdn.net/julius_lee/article/details/8466560
我的wx版本是
打开__version__.py 文件
如下# This file was generated by setup.py...
VERSION_STRING = '3.0.0.0'
MAJOR_VERSION = 3
MINOR_VERSION = 0
RELEASE_VERSION = 0
SUBREL_VERSION = 0
VERSION = (MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION,
SUBREL_VERSION, '')
我的版本是 3.0.修改上面的2.8就可以啦。
0 0
- AttributeError: 'module' object has no attribute 'Frame' 解决方法
- AttributeError: 'module' object has no attribute 'Frame' 解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- 解决方法——AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'
- Scrapy AttributeError: 'module' object has no attribute 'OP_NO_TLSv1_1 解决方法
- AttributeError: 'module' object has no attribute 'getpass'
- AttributeError: 'module' object has no attribute 'Serial'
- AttributeError: 'module' object has no attribute(转)
- AttributeError: 'module' object has no attribute 'randint'
- AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
- AttributeError: 'module' object has no attribute 'Serial'
- AttributeError: 'module' object has no attribute 'LabelMap'
- AttributeError: 'module' object has no attribute 'XXX'
- AttributeError: 'module' object has no attribute 'urlopen'
- AttributeError:'module' object has no attribute 'classify'
- linux---ext3grep---防止误删的工具
- 5个国内优秀网站
- HDU1754 I Hate It(线段树)
- spring +struts2 + ibatis + mysql 案例配置
- UVa:1411 Ants(KM算法)
- AttributeError: 'module' object has no attribute 'Frame' 解决方法
- Mymind教学系列--Github上的免费且强大思维导图工具-(一)
- linux常用查看硬件设备信息命令
- Spring【IOC】【AOP】
- struts2-校验框架
- Tomcat:IOException while loading persisted sessions: java
- bower install js使用bower管理js
- 欧拉计划 Java实现
- gcc创建,使用动态库