wxversion cross-platform weirdness

Hi,

I have just discovered the wxversion module. Am I right in thinking that every distributed wxPython application should be using it? If I understand correctly, any user of a wxPython application who has multiple versions of wxPython installed is at major risk of problems if the application doesn't specify the particular version it needs.

The weirdness I refer to relates to sys.path. If I do the following:

import wxversion
wxversion.select("2.8")
import wx

... and then look at sys.path, I expect to see an entry at the start for wx. In Ubuntu (9.10) I see the following:

['/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode',
'/home/ ...'
...

In Windows XP, however, the reference to wx came up twice:

['C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
  'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
  'C:\\Program Files\\ ...',
...

Is that deliberate? What it means is that I can't just get the working path from sys.path[1]. I have a simple workaround but it still seems a little weird.

All the best, Grant

Hi,

I have just discovered the wxversion module. Am I right in thinking that every distributed wxPython application should be using it? If I understand correctly, any user of a wxPython application who has multiple versions of wxPython installed is at major risk

"major risk" - what do you see as a major risk here? In my view it is up to the application developer to ensure the correct version of any library needed by his application. If you distribute in source then with wxPython you would use wxversion to ensure the correct version or throw an error if nothing "usable" is the users machine. If you distribute in .exe format then you ensure the right version when you do the build.

of problems if the application doesn't specify the particular version it needs.

The weirdness I refer to relates to sys.path. If I do the following:

import wxversion
wxversion.select("2.8")
import wx

... and then look at sys.path, I expect to see an entry at the start for wx. In Ubuntu (9.10) I see the following:

['/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode',
'/home/ ...'
...

In Windows XP, however, the reference to wx came up twice:

['C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\Program Files\\ ...',
...

Is that deliberate?

Probably not, I actually see three entries. I am sure Robin or someone else will enlighten us how this might happen.

  What it means is that I can't just get the working path from sys.path[1]. I have a simple workaround but it still seems a little weird.

"current working path"? I would use:

import os
os.getcwd()

Or maybe the following, but then I wonder why you would need to know where wx is located in your code?

wx.__file__

Werner

···

On 26/03/2010 08:17, Grant Paton-Simpson wrote:

Hi,

I have just discovered the wxversion module. Am I right in thinking that
every distributed wxPython application should be using it? If I
understand correctly, any user of a wxPython application who has
multiple versions of wxPython installed is at major risk of problems if
the application doesn't specify the particular version it needs.

The weirdness I refer to relates to sys.path. If I do the following:

import wxversion
wxversion.select("2.8")
import wx

... and then look at sys.path, I expect to see an entry at the start for
wx. In Ubuntu (9.10) I see the following:

['/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode',
'/home/ ...'
...

In Windows XP, however, the reference to wx came up twice:

['C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\Program Files\\ ...',
...

Is that deliberate?

wxversion just attempts to insert an item in the sys.path such that the selected version of wxPython will be found first. It does not remove others that may already be there because of .pth files, PYTHONPATH, or whatever.

What it means is that I can't just get the working
path from sys.path[1]. I have a simple workaround but it still seems a
little weird.

As mentioned already, wx.__file__ would be the right way to know which one was actually imported.

···

On 3/26/10 12:17 AM, Grant Paton-Simpson wrote:

--
Robin Dunn
Software Craftsman

Thanks for the explanation of what wxversion is actually doing.

As for my comment on knowing which path the script is in, I am
referring to the script I am running, not the wx script. Nice to know
about wx.__file__ though.

BTW the reason I use sys.path to work out the current location instead
of __file__ is because it works even within an interpreter like IDLE.
I needed this to be the case because sometimes people want to run a
faulty script from within IDLE to debug it. I wouldn't be surprised
if there are better solutions but what I currently do works (after a
fashion).

···

On Mar 27, 1:47 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 3/26/10 12:17 AM, Grant Paton-Simpson wrote:

> Hi,

> I have just discovered the wxversion module. Am I right in thinking that
> every distributed wxPython application should be using it? If I
> understand correctly, any user of a wxPython application who has
> multiple versions of wxPython installed is at major risk of problems if
> the application doesn't specify the particular version it needs.

> The weirdness I refer to relates to sys.path. If I do the following:

> import wxversion
> wxversion.select("2.8")
> import wx

> ... and then look at sys.path, I expect to see an entry at the start for
> wx. In Ubuntu (9.10) I see the following:

> ['/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode',
> '/home/ ...'
> ...

> In Windows XP, however, the reference to wx came up twice:

> ['C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
> 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode',
> 'C:\\Program Files\\ ...',
> ...

> Is that deliberate?

wxversion just attempts to insert an item in the sys.path such that the
selected version of wxPython will be found first. It does not remove
others that may already be there because of .pth files, PYTHONPATH, or
whatever.

> What it means is that I can't just get the working
> path from sys.path[1]. I have a simple workaround but it still seems a
> little weird.

As mentioned already, wx.__file__ would be the right way to know which
one was actually imported.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org