AttributeError: 'module' object has no attribute 'Frame' 解决方法
2014-02-28 20:38
1141 查看
最近对wxpython的GUI编程试用了下,试用过程中出现报错:
[python]
view plaincopyprint?
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要使用的版本号
[python]
view plaincopyprint?
import wxversion
wxversion.select('2.8')
import wx
对于版本号的确认可以参考自己的安装文件或py文件;
找到 C:\Python27\Lib\site-packages 目录下的wxversion.py文件
说明如下:
[python]
view plaincopyprint?
#----------------------------------------------------------------------
# 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的。
[python]
view plaincopyprint?
>>> 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就可以啦。
最近对wxpython的GUI编程试用了下,试用过程中出现报错:
[python]
view plaincopyprint?
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'
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要使用的版本号
[python]
view plaincopyprint?
import wxversion
wxversion.select('2.8')
import wx
import wxversion wxversion.select('2.8') import wx
对于版本号的确认可以参考自己的安装文件或py文件;
找到 C:\Python27\Lib\site-packages 目录下的wxversion.py文件
说明如下:
[python]
view plaincopyprint?
#----------------------------------------------------------------------
# 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
"""
#---------------------------------------------------------------------- # 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 """我就是用egg安装不准确,然后从工作正常的机器上拷贝了wx-2.8-msw-unicode 这个文件夹放到C:\Python27\Lib\site-packages 下,再加上导入之前指定版本,就工作正常了
希望对发现有同样问题的人有点帮助,这个问题之前就花了我很多时间一直没搞定,后来到公司的电脑比较了下才ok的。
[python]
view plaincopyprint?
>>> print wx.version()
2.8.12.1 (msw-unicode)
>>> 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就可以啦。
相关文章推荐
- Keras深度学习框架学习笔记(3) - AttributeError:’module’ object has no attribute ‘ifelse’错误信息的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- 解决方法——AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'
- AttributeError: 'module' object has no attribute 'Frame' 解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- Scrapy AttributeError: 'module' object has no attribute 'OP_NO_TLSv1_1 解决方法
- AttributeError: 'module' object has no attribute '_handlerList' 错误解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- AttributeError: 'module' object has no attribute 'face' 问题解决 opencv+python
- [置顶] AttributeError: 'module' object has no attribute '_base' 可行解决办法
- Ubuntu运行scrapy报“scrapy: 'module' object has no attribute 'OP_SINGLE_ECDH_USE'错误解决方法”
- import json后,报错:AttributeError: 'module' object has no attribute 'dumps,原因分析及解决方法
- AttributeError: 'NoneType' object has no attribute 'sc' 解决方法(二)
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- AttributeError: 'WebDriver' object has no attribute 'switchTo' 解决方法