importing from wx stated producing AttributeError in "wx-2.8-msw-unicode\wx\_core.py"

Hi Fellow Pythonians,

After a Windows reboot, I found that something is wrong with my wxPython installation.

I reduce my script to the following one liner, to demonstrate the problem:

$ cat test.py#! /usr/bin/env python

from wx import xrc

$ python test.py’import site’ failed; use -v for traceback
Traceback (most recent call last):
File “test.py”, line 3, in
from wx import xrc
File “D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\xrc.py”, line 59, in
import _core
File “D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx_core.py”, line 14472, in
default = locale.getdefaultlocale()[1]
AttributeError: ‘module’ object has no attribute ‘getdefaultlocale’

$

Googling produced http://osdir.com/ml/python.wxpython.devel/2006-12/msg00012.html, but following its advice -and exchanging the line

except (ValueError, LookupError, TypeError): with except (ValueError, LookupError, TypeError, AttributeError):

broke so many other things that it doesn’t seem to be a valid solution to my problem.

Can anyone guess why I stated getting these errors ?

My environment is:

Windows XP, Python 2.5, cygwin.

Thanks,

Ron.

Hi Fellow Pythonians,

tmp.txt (5.22 KB)

···

After a Windows reboot, I found that something is wrong with my wxPython installation.

I reduce my script to the following one liner, to demonstrate the problem:

$ cat test.py #! /usr/bin/env python

from wx import xrc

** $ python test.py**‘import site’ failed; use -v for traceback
Traceback (most recent call last):
File “test.py”, line 3, in
from wx import xrc
File “D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\xrc.py”, line 59, in
import _core
File “D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx_core.py”, line 14472, in
default = locale.getdefaultlocale()[1]
AttributeError: ‘module’ object has no attribute ‘getdefaultlocale’

$

Googling produced http://osdir.com/ml/python.wxpython.devel/2006-12/msg00012.html , but following its advice -and exchanging the line

except (ValueError, LookupError, TypeError): with except (ValueError, LookupError, TypeError, AttributeError):

broke so many other things that it doesn’t seem to be a valid solution to my problem.

Can anyone guess why I star ted getting these errors ?

My environment is:

Windows XP, Python 2.5, cygwin.

Thanks,

Ron.

P.S.: the output of python -v ./test.py is attached.


Ron,

Barak, Ron wrote:

Hi Fellow Pythonians,

         After a Windows reboot, I found that something is wrong with my
    wxPython installation.
         I reduce my script to the following one liner, to demonstrate the
    problem:
         *$ cat test.py
    *#! /usr/bin/env python
         from wx import xrc
         *$ python test.py
    *'import site' failed; use -v for traceback
    Traceback (most recent call last):
      File "test.py", line 3, in <module>
        from wx import xrc
      File
    "D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\xrc.py", line
    59, in <module>
        import _core
      File
    "D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
    line 14472, in <module>
        default = locale.getdefaultlocale()[1]
    AttributeError: 'module' object has no attribute 'getdefaultlocale'

I didn't try your script, but just did this in the Boa shell.

from wx import xrc
>>> import locale
>>> locale.getdefaultlocale
<function getdefaultlocale at 0x01B671B0>

to me your problem doesn't look like there is something wrong with your wxPython install, but something "stepped" onto your locale module.

Werner

Ron,

Your mailer is using an 8pt font for your email, which on my screen makes the text almost unreadable, especially the magenta and light blue text. If you can, please either tell your mail application to not used fixed point sizes but relative sizes (so it will use the font size settings in the readers as the base size, not the tiny 8 points.) or use plain text with no formatting.

Barak, Ron wrote:

# d:\Python25\lib\types.pyc matches d:\Python25\lib\types.py
import types # precompiled from d:\Python25\lib\types.pyc
import _types # builtin
import locale # directory D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\locale
import locale # precompiled from D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\locale\__init__.pyc

It looks like two problems to me:

1. D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx should not be on your python path, just the parent of that dir. (If it wasn't on the path then it wouldn't check if that locale folder was a python package.) Look in the wx.pth file for what it is putting on the path.

2. The locale directory above is not a Python package and so it should not have an __init__ module in it. How did it get there?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Werner,

When I tried to duplicate your lines, I get the errors in the (red) lines below.

I tried re-installing python and wxPython, but the error remains.

C:\Documents and Settings\RBARAK>python -v

installing zipimport hook

import zipimport # builtin

installed zipimport hook

D:\Python25\lib\site.pyc has bad mtime

D:\Python25\lib\site.py: inconsistent use of tabs and spaces in indentation
import site # from D:\Python25\lib\site.py

wrote D:\Python25\lib\site.pyc

D:\Python25\lib\os.pyc matches D:\Python25\lib\os.py

import os # precompiled from D:\Python25\lib\os.pyc
import errno # builtin
import nt # builtin

D:\Python25\lib\ntpath.pyc matches D:\Python25\lib\ntpath.py

import ntpath # precompiled from D:\Python25\lib\ntpath.pyc

D:\Python25\lib\stat.pyc matches D:\Python25\lib\stat.py

import stat # precompiled from D:\Python25\lib\stat.pyc

D:\Python25\lib\UserDict.pyc matches D:\Python25\lib\UserDict.py

import UserDict # precompiled from D:\Python25\lib\UserDict.pyc

D:\Python25\lib\copy_reg.pyc matches D:\Python25\lib\copy_reg.py

import copy_reg # precompiled from D:\Python25\lib\copy_reg.pyc

D:\Python25\lib\types.pyc matches D:\Python25\lib\types.py

import types # precompiled from D:\Python25\lib\types.pyc
import types # builtin
import locale # directory D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lo
cale
import locale # precompiled from D:\Python25\Lib\site-packages\wx-2.8-msw-unicod
e\wx\locale_init
.pyc

D:\Python25\lib\codecs.pyc matches D:\Python25\lib\codecs.py

import codecs # precompiled from D:\Python25\lib\codecs.pyc
import _codecs # builtin
import encodings # directory D:\Python25\lib\encodings

D:\Python25\lib\encodings_init_.pyc matches D:\Python25\lib\encodings__ini

t__.py
import encodings # precompiled from D:\Python25\lib\encodings_init_.pyc

D:\Python25\lib\encodings\aliases.pyc matches D:\Python25\lib\encodings\aliase

s.py
import encodings.aliases # precompiled from D:\Python25\lib\encodings\aliases.py
c
‘import site’ failed; traceback:
Traceback (most recent call last):
File “D:\Python25\lib\site.py”, line 418, in
main()
File “D:\Python25\lib\site.py”, line 409, in main
aliasmbcs()
File “D:\Python25\lib\site.py”, line 358, in aliasmbcs
enc = locale.getdefaultlocale()[1]
AttributeError: ‘module’ object has no attribute ‘getdefaultlocale’

D:\Python25\lib\warnings.pyc matches D:\Python25\lib\warnings.py

import warnings # precompiled from D:\Python25\lib\warnings.pyc

D:\Python25\lib\linecache.pyc matches D:\Python25\lib\linecache.py

import linecache # precompiled from D:\Python25\lib\linecache.pyc
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type “help”, “copyright”, “credits” or “license” for more information.

D:\Python25\lib\encodings\cp862.pyc matches D:\Python25\lib\encodings\cp862.py

import encodings.cp862 # precompiled from D:\Python25\lib\encodings\cp862.pyc

import locale
locale.getdefaultlocale
Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘module’ object has no attribute ‘getdefaultlocale’

Any suggestions how to make my Python+wx operational again ?

Bye,

Ron.

···

From: Werner F. Bruhin
Sent: Monday, 08 September, 2008 17:47
To:
wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] importing from wx started producing AttributeError in “wx-2.8-msw-unicode\wx_core.py” (update 1)

Ron,

Barak, Ron wrote:

Hi Fellow Pythonians,

After a Windows reboot, I found that something is wrong with my
wxPython installation.

I reduce my script to the following one liner, to demonstrate the
problem:

*$ cat test.py
*#! /usr/bin/env python

from wx import xrc

*$ python test.py
*'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    from wx import xrc
  File
"D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\xrc.py", line
59, in <module>
    import _core
  File
"D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 14472, in <module>
    default = locale.getdefaultlocale()[1]
AttributeError: 'module' object has no attribute 'getdefaultlocale'

I didn’t try your script, but just did this in the Boa shell.

from wx import xrc

import locale
locale.getdefaultlocale
<function getdefaultlocale at 0x01B671B0>

to me your problem doesn’t look like there is something wrong with your wxPython install, but something “stepped” onto your locale module.

Werner

Ron,

Barak, Ron wrote:

Hi Werner,
When I tried to duplicate your lines, I get the errors in the (red) lines below.
I tried re-installing python and wxPython, but the error remains.
C:\Documents and Settings\RBARAK>python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# D:\Python25\lib\site.pyc has bad mtime
D:\Python25\lib\site.py: inconsistent use of tabs and spaces in indentation
import site # from D:\Python25\lib\site.py
# wrote D:\Python25\lib\site.pyc
# D:\Python25\lib\os.pyc matches D:\Python25\lib\os.py
import os # precompiled from D:\Python25\lib\os.pyc
import errno # builtin
import nt # builtin
# D:\Python25\lib\ntpath.pyc matches D:\Python25\lib\ntpath.py
import ntpath # precompiled from D:\Python25\lib\ntpath.pyc
# D:\Python25\lib\stat.pyc matches D:\Python25\lib\stat.py
import stat # precompiled from D:\Python25\lib\stat.pyc
# D:\Python25\lib\UserDict.pyc matches D:\Python25\lib\UserDict.py
import UserDict # precompiled from D:\Python25\lib\UserDict.pyc
# D:\Python25\lib\copy_reg.pyc matches D:\Python25\lib\copy_reg.py
import copy_reg # precompiled from D:\Python25\lib\copy_reg.pyc
# D:\Python25\lib\types.pyc matches D:\Python25\lib\types.py
import types # precompiled from D:\Python25\lib\types.pyc
import _types # builtin
import locale # directory D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lo
cale
import locale # precompiled from D:\Python25\Lib\site-packages\wx-2.8-msw-unicod
e\wx\locale\__init__.pyc
# D:\Python25\lib\codecs.pyc matches D:\Python25\lib\codecs.py
import codecs # precompiled from D:\Python25\lib\codecs.pyc
import _codecs # builtin
import encodings # directory D:\Python25\lib\encodings
# D:\Python25\lib\encodings\__init__.pyc matches D:\Python25\lib\encodings\__ini
t__.py
import encodings # precompiled from D:\Python25\lib\encodings\__init__.pyc
# D:\Python25\lib\encodings\aliases.pyc matches D:\Python25\lib\encodings\aliase
s.py
import encodings.aliases # precompiled from D:\Python25\lib\encodings\aliases.py
c
'import site' failed; traceback:
Traceback (most recent call last):
  File "D:\Python25\lib\site.py", line 418, in <module>
    main()
  File "D:\Python25\lib\site.py", line 409, in main
    aliasmbcs()
  File "D:\Python25\lib\site.py", line 358, in aliasmbcs
    enc = locale.getdefaultlocale()[1]
AttributeError: 'module' object has no attribute 'getdefaultlocale'
# D:\Python25\lib\warnings.pyc matches D:\Python25\lib\warnings.py
import warnings # precompiled from D:\Python25\lib\warnings.pyc
# D:\Python25\lib\linecache.pyc matches D:\Python25\lib\linecache.py
import linecache # precompiled from D:\Python25\lib\linecache.pyc
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
# D:\Python25\lib\encodings\cp862.pyc matches D:\Python25\lib\encodings\cp862.py
import encodings.cp862 # precompiled from D:\Python25\lib\encodings\cp862.pyc
>>> import locale
>>> locale.getdefaultlocale
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getdefaultlocale'
>>>
Any suggestions how to make my Python+wx operational again ?

I am no expert in this, but to me it looks like your Python 25 install is somehow damaged/changed causing this problem.

If you look at the above you see that already aliases.py is failing with the same error.

Did you see Robin's response, he also commented that something did not look right in the wxPython install.

I would reinstall Python 2.5 and probably also wxPython.

Werner

Hi Werner,

Reinstalling python+wxPython did not solve the problem.
I reinstalled the OS from scratch, and after a day's work getting to somewhat where I was, the above problem disappeared.
Thanks for all the wise suggestions.
Ron.

···

-----Original Message-----
From: Werner F. Bruhin
Sent: Tuesday, September 09, 2008 11:42
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] importing from wx started producing AttributeError in "wx-2.8-msw-unicode\wx\_core.py" (update 1)

Ron,

Barak, Ron wrote:

Hi Werner,

When I tried to duplicate your lines, I get the errors in the (red)
lines below.
I tried re-installing python and wxPython, but the error remains.

C:\Documents and Settings\RBARAK>python -v # installing zipimport hook
import zipimport # builtin # installed zipimport hook #
D:\Python25\lib\site.pyc has bad mtime
D:\Python25\lib\site.py: inconsistent use of tabs and spaces in
indentation import site # from D:\Python25\lib\site.py # wrote
D:\Python25\lib\site.pyc # D:\Python25\lib\os.pyc matches
D:\Python25\lib\os.py import os # precompiled from
D:\Python25\lib\os.pyc import errno # builtin import nt # builtin #
D:\Python25\lib\ntpath.pyc matches D:\Python25\lib\ntpath.py import
ntpath # precompiled from D:\Python25\lib\ntpath.pyc #
D:\Python25\lib\stat.pyc matches D:\Python25\lib\stat.py import stat #
precompiled from D:\Python25\lib\stat.pyc #
D:\Python25\lib\UserDict.pyc matches D:\Python25\lib\UserDict.py
import UserDict # precompiled from D:\Python25\lib\UserDict.pyc #
D:\Python25\lib\copy_reg.pyc matches D:\Python25\lib\copy_reg.py
import copy_reg # precompiled from D:\Python25\lib\copy_reg.pyc #
D:\Python25\lib\types.pyc matches D:\Python25\lib\types.py import
types # precompiled from D:\Python25\lib\types.pyc import _types #
builtin import locale # directory
D:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lo
cale
import locale # precompiled from
D:\Python25\Lib\site-packages\wx-2.8-msw-unicod
e\wx\locale\__init__.pyc
# D:\Python25\lib\codecs.pyc matches D:\Python25\lib\codecs.py import
codecs # precompiled from D:\Python25\lib\codecs.pyc import _codecs #
builtin import encodings # directory D:\Python25\lib\encodings #
D:\Python25\lib\encodings\__init__.pyc matches
D:\Python25\lib\encodings\__ini t__.py import encodings # precompiled
from D:\Python25\lib\encodings\__init__.pyc
# D:\Python25\lib\encodings\aliases.pyc matches
D:\Python25\lib\encodings\aliase s.py import encodings.aliases #
precompiled from D:\Python25\lib\encodings\aliases.py
c
'import site' failed; traceback:
Traceback (most recent call last):
  File "D:\Python25\lib\site.py", line 418, in <module>
    main()
  File "D:\Python25\lib\site.py", line 409, in main
    aliasmbcs()
  File "D:\Python25\lib\site.py", line 358, in aliasmbcs
    enc = locale.getdefaultlocale()[1]
AttributeError: 'module' object has no attribute 'getdefaultlocale'
# D:\Python25\lib\warnings.pyc matches D:\Python25\lib\warnings.py
import warnings # precompiled from D:\Python25\lib\warnings.pyc #
D:\Python25\lib\linecache.pyc matches D:\Python25\lib\linecache.py
import linecache # precompiled from D:\Python25\lib\linecache.pyc
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
# D:\Python25\lib\encodings\cp862.pyc matches
D:\Python25\lib\encodings\cp862.py

import encodings.cp862 # precompiled from
D:\Python25\lib\encodings\cp862.pyc
>>> import locale
>>> locale.getdefaultlocale
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getdefaultlocale'
>>>

Any suggestions how to make my Python+wx operational again ?

I am no expert in this, but to me it looks like your Python 25 install is somehow damaged/changed causing this problem.

If you look at the above you see that already aliases.py is failing with the same error.

Did you see Robin's response, he also commented that something did not look right in the wxPython install.

I would reinstall Python 2.5 and probably also wxPython.

Werner