Namespace Diff Tool import dichotomy (!)

I remember seeing or hearing about this talk on custom importers. I don’t know if it will help, but maybe: http://python.mirocommunity.org/video/1491/pycon-2010-import-this-that-an

Hi Andrea,

...

Thanks for the suggestion, and I'll definitely go this way at some point. However, it appears not to solve the underlying problem on how to import stuff correctly. Let's assume for the moment the following:

1) I run on Windows Vista and 7
2) I'm using Python 2.7;
3) I have wxPython 2.8.10 and 2.9.2.4 in site-packages. The default version (specified in wx.pth) is 2.9.2.4;
4) I want to analyze wxPython 2.8.10 (not the default one).

These are the conclusions I could draw up to now, and they are true regardless if you run the importing/analyzing stuff in a separate thread or separate process or on the main thread or anywhere else:

This is way over my head.

Shouldn't that get resolved too if you start a new process and do this at the beginning before you do import wx?

import wxversion
wxversion.select('2.8.10')

Werner

Hi Werner,

Hi Andrea,

Thanks for the suggestion, and I’ll definitely go this way at some point. However, it appears not to solve the underlying problem on how to import stuff correctly. Let’s assume for the moment the following:

  1. I run on Windows Vista and 7

  2. I’m using Python 2.7;

  3. I have wxPython 2.8.10 and 2.9.2.4 in site-packages. The default version (specified in wx.pth) is 2.9.2.4;

  4. I want to analyze wxPython 2.8.10 (not the default one).

These are the conclusions I could draw up to now, and they are true regardless if you run the importing/analyzing stuff in a separate thread or separate process or on the main thread or anywhere else:

This is way over my head.

Shouldn’t that get resolved too if you start a new process and do this at the beginning before you do import wx?

import wxversion

wxversion.select(‘2.8.10’)

This will work for wx only, as other libraries do not have the “wxversion” concept. For example, I have 3 versions of Sphinx and 2 of SQLAlchemy on my system (I know, I should clean up a bit…), how would I go to differentiate them? However, your suggestion gave me a couple of other ideas to test, and hopefully I will get this thing sorted out by tomorrow.

The removal of import by filename by the Python crew was almost as inspired as the print vs. print() modification. A couple of other nice touches like these two and I’ll switch to C# full time (and not half time as it is now).

Thank you for your suggestion.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

···

On 3 November 2011 18:24, werner wrote:

Hi Andrea,

···

On Thu, Nov 3, 2011 at 4:12 PM, Andrea Gavana andrea.gavana@gmail.com wrote:

Hi Werner,

On 3 November 2011 18:24, werner wrote:

Hi Andrea,

Thanks for the suggestion, and I’ll definitely go this way at some point. However, it appears not to solve the underlying problem on how to import stuff correctly. Let’s assume for the moment the following:

  1. I run on Windows Vista and 7

  2. I’m using Python 2.7;

  3. I have wxPython 2.8.10 and 2.9.2.4 in site-packages. The default version (specified in wx.pth) is 2.9.2.4;

  4. I want to analyze wxPython 2.8.10 (not the default one).

These are the conclusions I could draw up to now, and they are true regardless if you run the importing/analyzing stuff in a separate thread or separate process or on the main thread or anywhere else:

This is way over my head.

Shouldn’t that get resolved too if you start a new process and do this at the beginning before you do import wx?

import wxversion

wxversion.select(‘2.8.10’)

This will work for wx only, as other libraries do not have the “wxversion” concept. For example, I have 3 versions of Sphinx and 2 of SQLAlchemy on my system (I know, I should clean up a bit…), how would I go to differentiate them? However, your suggestion gave me a couple of other ideas to test, and hopefully I will get this thing sorted out by tomorrow.

The removal of import by filename by the Python crew was almost as inspired as the print vs. print() modification. A couple of other nice touches like these two and I’ll switch to C# full time (and not half time as it is now).

Thank you for your suggestion.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

Well, the other modules don’t have the handy “select” method, but most well-designed modules include a version property, so something like this should work:

import sqlalchemy

version = sqlalchemy.version


Mike Driscoll

Blog: http://blog.pythonlibrary.org

Hi Mike,

Hi Andrea,

Hi Werner,

Hi Andrea,

Thanks for the suggestion, and I’ll definitely go this way at some point. However, it appears not to solve the underlying problem on how to import stuff correctly. Let’s assume for the moment the following:

  1. I run on Windows Vista and 7

  2. I’m using Python 2.7;

  3. I have wxPython 2.8.10 and 2.9.2.4 in site-packages. The default version (specified in wx.pth) is 2.9.2.4;

  4. I want to analyze wxPython 2.8.10 (not the default one).

These are the conclusions I could draw up to now, and they are true regardless if you run the importing/analyzing stuff in a separate thread or separate process or on the main thread or anywhere else:

This is way over my head.

Shouldn’t that get resolved too if you start a new process and do this at the beginning before you do import wx?

import wxversion

wxversion.select(‘2.8.10’)

This will work for wx only, as other libraries do not have the “wxversion” concept. For example, I have 3 versions of Sphinx and 2 of SQLAlchemy on my system (I know, I should clean up a bit…), how would I go to differentiate them? However, your suggestion gave me a couple of other ideas to test, and hopefully I will get this thing sorted out by tomorrow.

The removal of import by filename by the Python crew was almost as inspired as the print vs. print() modification. A couple of other nice touches like these two and I’ll switch to C# full time (and not half time as it is now).

Thank you for your suggestion.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

Well, the other modules don’t have the handy “select” method, but most well-designed modules include a version property, so something like this should work:

import sqlalchemy

version = sqlalchemy.version

They do, of course (well, most of them, with notable exceptions like xlrd/xlwt, cx_freeze, etc…), but that doesn’t mean you will be able to import the version you want: if I have 3 sqlalchemy versions, and you do:

import(“sqlalchemy”)

which one of them will get imported? The first one on sys.path? The one reported in the pth file? You can see it for yourself if you have more than one wxPython version installed. Without using wxversion, try and import everything (sub-packages, sub-modules and so on) not related to your default wxPython version.

Anyway, I believe I have solved this issue in the end (fingers crossed…), although I am not sure it was worth the effort.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.alice.it/infinity77/

···

On 3 November 2011 23:24, Mike Driscoll wrote:

On Thu, Nov 3, 2011 at 4:12 PM, Andrea Gavana andrea.gavana@gmail.com wrote:

On 3 November 2011 18:24, werner wrote:

If you used easy_install then this will do:

    import pkg_resources

    pkg_resources.require("sqlalchemy") # get latest version

##    pkg_resources.require("sqlalchemy==0.5.8") # get specific

version

Otherwise you probably have to "move" things around before starting

up the process to get the “non” standard version.

Werner
···

On 11/03/2011 10:12 PM, Andrea Gavana wrote:

Hi Werner,

On 3 November 2011 18:24, werner wrote:

Hi Andrea,

      ...
          Thanks for the suggestion, and I'll definitely go this way

at some point. However, it appears not to solve the
underlying problem on how to import stuff correctly. Let’s
assume for the moment the following:

          1) I run on Windows Vista and 7

          2) I'm using Python 2.7;

          3) I have wxPython 2.8.10 and 2.9.2.4 in site-packages.

The default version (specified in wx.pth) is 2.9.2.4;

          4) I want to analyze wxPython 2.8.10 (not the default

one).

          These are the conclusions I could draw up to now, and they

are true regardless if you run the importing/analyzing
stuff in a separate thread or separate process or on the
main thread or anywhere else:

This is way over my head.

      Shouldn't that get resolved too if you start a new process and

do this at the beginning before you do import wx?

      import wxversion

      wxversion.select('2.8.10')
      This will work for wx only, as other libraries do not have

the “wxversion” concept. For example, I have 3 versions of
Sphinx and 2 of SQLAlchemy on my system (I know, I should
clean up a bit…), how would I go to differentiate them?
However, your suggestion gave me a couple of other ideas to
test, and hopefully I will get this thing sorted out by
tomorrow.

There’s some way to do it with virtualenv. I think it may be the virtualenvwrapper. I saw a presentation on it at our local Python group one time and it was pretty slick. I don’t know how that could be integrated here though. Just thought I’d mention it.

···

On Thu, Nov 3, 2011 at 5:23 PM, werner wbruhin@free.fr wrote:

On 11/03/2011 10:12 PM, Andrea Gavana wrote:

Hi Werner,

On 3 November 2011 18:24, werner wrote:

Hi Andrea,

      ...
          Thanks for the suggestion, and I'll definitely go this way

at some point. However, it appears not to solve the
underlying problem on how to import stuff correctly. Let’s
assume for the moment the following:

          1) I run on Windows Vista and 7

          2) I'm using Python 2.7;

          3) I have wxPython 2.8.10 and 2.9.2.4 in site-packages.

The default version (specified in wx.pth) is 2.9.2.4;

          4) I want to analyze wxPython 2.8.10 (not the default

one).

          These are the conclusions I could draw up to now, and they

are true regardless if you run the importing/analyzing
stuff in a separate thread or separate process or on the
main thread or anywhere else:

This is way over my head.

      Shouldn't that get resolved too if you start a new process and

do this at the beginning before you do import wx?

      import wxversion

      wxversion.select('2.8.10')
      This will work for wx only, as other libraries do not have

the “wxversion” concept. For example, I have 3 versions of
Sphinx and 2 of SQLAlchemy on my system (I know, I should
clean up a bit…), how would I go to differentiate them?
However, your suggestion gave me a couple of other ideas to
test, and hopefully I will get this thing sorted out by
tomorrow.

If you used easy_install then this will do:

    import pkg_resources

    pkg_resources.require("sqlalchemy") # get latest version

##    pkg_resources.require("sqlalchemy==0.5.8") # get specific

version

Otherwise you probably have to "move" things around before starting

up the process to get the “non” standard version.

Werner

Mike Driscoll

Blog: http://blog.pythonlibrary.org