AttributeError:'module'object has no attribute'Frame'解決方法

4191 ワード

最近、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が1つ以上インストールされているか、またはバージョンが正確ではない可能性があります.以下の方法で解決できます.
ファイルの先頭にimportで使用するバージョン番号を追加
import wxversion
wxversion.select('2.8')
import wx

バージョン番号の確認には、自分のインストールファイルまたはpyファイルを参照できます.
C:Python 27Libsite-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

"""
私はeggでインストールするのが正確ではありませんて、それから仕事の正常な機械の上からwx-2.8-msw-unicodeこのフォルダをコピーしてC:Python 27Libsite-packagesの下に置いて、更に導入する前に指定するバージョンを加えて、仕事は正常です
同じ問題を発見した人に少し役に立つことを望んで、この問題は前から私に多くの時間を費やしてずっと解決していないで、それから会社のパソコンに行って比較してやっとokになりました.
>>> print wx.version()
2.8.12.1 (msw-unicode)