A little more investigation has shown this. The following code does not work on a Mac with new versions of wxPython.

def CheckForWx():
    """Try to import wx module and check its version"""

    majorVersion = 2.8
    minorVersion = 1.1

    try:
        import wxversion
        wxversion.select(str(majorVersion))
        import wx

The problem lies in wxversion.select. It is looking for the SOURCE CODE files in a BINARY wxPython installation. They simply are not there. Here is what happens if I run this in the Python interpreter.

>>> import wx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
File "//Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/wx-2.8-mac-unicode/wx/__init__.py", line 45, in <module> File "//Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 4, in <module>
ImportError: No module named _core_
>>>

Note, it is checking for _core.py.
I have _core.pyo and _core.pyc, but not the source _core.py. I don't have any source files in this binary installation. It works fine and takes up less space I suppose. But this sequence ...

import wxversion
wxversion.select(str(majorVersion))
import wx

...fails not because I have the wrong version, but because I do not have the SOURCE files that it uses to check for the version. This is a bug in wxversion. It should be looking for _core.*, not a specific source file _core.py. If I disable version checking by putting a return at the beginning of CheckForWx(), wxgui loads and runs fine. But we should have a version check (though I don't know if we need to check it in so many modules; at startup should be enough.

The following code works fine.

def CheckForWx():
    """Try to import wx module and check its version"""

    majorVersion = 2.8
    minorVersion = 1.1

    try:
        #import wxversion
        #wxversion.select(str(majorVersion))
        import wx
        version = wx.version().split(' ')[0]
        if float(version[:3]) < majorVersion:
raise ValueError('You are using wxPython version %s' % str(version))
        if float(version[:3]) == 2.8 and \
                float(version[4:]) < minorVersion:
raise ValueError('You are using wxPython version %s' % str(version))

This checks to make sure that the default wxpython installation is 2.8.1.1 or higher. If not, it throws an error and does not load wxgui.

Michael






On Jul 26, 2008, at 12:42 PM, Martin Landa wrote:

Micheal,

2008/7/26 Michael Barton <[EMAIL PROTECTED]>:
import wxversion
wxversion.select(str(2.8))
import wx
wx.__version__

'2.8.8.1'

This version check is failing with 2.8.8.0 on the Mac even if the correct
version is installed. It may be failing with other version too.
wx.__version__ looks for wxpython SOURCE (*.py) files that are not
currently being included in the wxpython binary installer for some reason.
The object files are correct and being installed (*.pyo).

Why not just use wx.version()? It gives the correct response regardless of
whether the source files are installed or not.

I changed CheckForWx() to use wx.version() instead of wx.__version__.
Hope it helps.

http://trac.osgeo.org/grass/changeset/32313

and

http://trac.osgeo.org/grass/changeset/32314

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/ ~landa *

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to