FAQ
Hello All.
I'm trying to 'compile-to-EXE' a python program which uses Win32 & WMI to
pull system info. from the PC such as serial number, CPU speed, etc. I'm
having problems with py2exe -- with regard to Win2000 & WinXP platforms. It
seems that the program only works if I have one typelib for WinXP and a
slightly different one for Win2000. Here is my relevent section from the
py2exe setup.py:
setup(
options = {"py2exe": {"typelibs":
## # typelib for WMI - WinXP
## [('{565783C6-CB41-11D1-8B02-00600806D9B6}', 0,
1, 2)],

# typelib for WMI - Win2000
[('{565783C6-CB41-11D1-8B02-00600806D9B6}', 0, 1,
1)],

# create a compressed zip archive
"compressed": 1,
"optimize": 2,
"packages": ["encodings"],
"excludes": excludes}},
# The lib directory contains everything except the executables and the
python dll.
# Can include a subdirectory name.
zipfile = "lib/shared.zip",

Can anyone tell me how I might make one unified py2exe setup.py that'll
'compile' for both Win2000 & WinXP?

If not, can someone give me a hint as to how I can have a python 'launcher'
which can determine the difference between Win2000 & WinXP? Using the
sys.platform, they both show as Win32.

Thanks!
Dave

Search Discussions

  • Tim Golden at May 24, 2005 at 2:36 pm

    Hello All.
    I'm trying to 'compile-to-EXE' a python program which uses
    Win32 & WMI to
    pull system info. from the PC such as serial number, CPU
    speed, etc. I'm
    having problems with py2exe -- with regard to Win2000 & WinXP
    platforms. It
    seems that the program only works if I have one typelib for
    WinXP and a
    slightly different one for Win2000. Here is my relevent
    section from the
    py2exe setup.py:
    [... snipped ...]
    Can anyone tell me how I might make one unified py2exe
    setup.py that'll
    'compile' for both Win2000 & WinXP?

    If not, can someone give me a hint as to how I can have a
    python 'launcher'
    which can determine the difference between Win2000 & WinXP? Using the
    sys.platform, they both show as Win32.

    Thanks!
    Dave
    There was a thread about this on the python-win32 list a
    while back. I think this is the start of the the thread
    (altho' it's a bit confusing). The conclusion seems to
    be that there's no conclusion. Maybe there's more info
    on the py2exe list/wiki?

    http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2007557

    As to the other question (which platform am I on) there
    was also a thread about this recently:

    http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/b87d5de8f91c8e9c?tvc=1&q=platform+&hl=en

    which, in short, says: use the platform module

    TJG

    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________
  • Thomas Heller at May 24, 2005 at 3:16 pm

    Tim Golden schrieb:
    Hello All.
    I'm trying to 'compile-to-EXE' a python program which uses
    Win32 & WMI to
    pull system info. from the PC such as serial number, CPU
    speed, etc. I'm
    having problems with py2exe -- with regard to Win2000 & WinXP
    platforms. It
    seems that the program only works if I have one typelib for
    WinXP and a
    slightly different one for Win2000. Here is my relevent
    section from the
    py2exe setup.py:
    [... snipped ...]
    Can anyone tell me how I might make one unified py2exe
    setup.py that'll
    'compile' for both Win2000 & WinXP?

    If not, can someone give me a hint as to how I can have a
    python 'launcher'
    which can determine the difference between Win2000 & WinXP? Using the
    sys.platform, they both show as Win32.

    Thanks!
    Dave
    There was a thread about this on the python-win32 list a
    while back. I think this is the start of the the thread
    (altho' it's a bit confusing). The conclusion seems to
    be that there's no conclusion. Maybe there's more info
    on the py2exe list/wiki?

    http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2007557
    I don't think something wnet into the wiki, unfortunately.
    The OP of the thread Tim mentions here already had a solution, if I
    understood him correctly, and the other things that were suggested
    didn't work. Basically, IIUC, he did add the typelib wrappers from the
    'other' windows version manually to the library.zip file.

    Totally different solutions would be:
    - change Tim's wmi.py module so that it works with dynamic binding (no
    typelib wrappers needed)
    or
    - change win32com so that the typelib wrappers can be generated by
    frozen executables at runtime.

    Thomas
  • Tim Golden at May 24, 2005 at 4:00 pm
    [Thomas Heller]

    [... snip problems with py2exe & WMI ...]
    The OP of the thread Tim mentions here already had a solution, if I
    understood him correctly, and the other things that were suggested
    didn't work. Basically, IIUC, he did add the typelib
    wrappers from the
    'other' windows version manually to the library.zip file.

    Totally different solutions would be:
    - change Tim's wmi.py module so that it works with dynamic
    binding (no
    typelib wrappers needed)
    or
    Well, if it helps, there's a version of the WMI module
    that uses dynamic binding on my site:

    http://timgolden.me.uk/python/downloads/wmi-0.6a.py

    I've hardcoded the relevant constants (which is pretty
    much all I was using early binding for) and replaced
    any other EnsureDispatch calls with simple Dispatch.

    Does anyone want to give it a try to let me know if
    it helps? I don't use py2exe myself.

    TJG


    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________
  • Thomas Heller at May 24, 2005 at 5:53 pm

    Tim Golden schrieb:
    [Thomas Heller]

    [... snip problems with py2exe & WMI ...]
    The OP of the thread Tim mentions here already had a solution, if I
    understood him correctly, and the other things that were suggested
    didn't work. Basically, IIUC, he did add the typelib
    wrappers from the
    'other' windows version manually to the library.zip file.

    Totally different solutions would be:
    - change Tim's wmi.py module so that it works with dynamic
    binding (no
    typelib wrappers needed)
    or
    Well, if it helps, there's a version of the WMI module
    that uses dynamic binding on my site:

    http://timgolden.me.uk/python/downloads/wmi-0.6a.py

    I've hardcoded the relevant constants (which is pretty
    much all I was using early binding for) and replaced
    any other EnsureDispatch calls with simple Dispatch.
    It may be dangerous since the constants may or may not be the same on
    different versions, at least in theory. I've appended a small module
    which allows to bind constants from the type library at runtime.
    Not much error checking, but you may get the idea. I'll leave providing
    a proper patch for pywin32, if it makes sense, to those that have more
    time ;-)
    Does anyone want to give it a try to let me know if
    it helps? I don't use py2exe myself.
    The simple test case I have works on XP (I don't use wmi myself, except
    as sample for py2exe).

    Thomas

    # constants.py

    class ProvideConstants(object):
    """A class which, when called on a win32com.client.Dispatch object,
    provides lazy access to constants defined in the typelib.

    They can be accessed as attributes of the _constants property."""
    def __init__(self, comobj):
    comobj.__dict__["_constants"] = self
    # Get the typelibrary's typecomp interface
    self.__typecomp = \
    comobj._oleobj_.GetTypeInfo().GetContainingTypeLib()[0].GetTypeComp()

    def __getattr__(self, name):
    if name.startswith("__") and name.endswith("__"):
    raise AttributeError, name
    result = self.__typecomp.Bind(name)
    # Bind returns a 2-tuple, first item is TYPEKIND,
    # the second item has the value
    if not result[0]:
    raise AttributeError, name
    return result[1].value

    if __name__ == "__main__":
    from win32com.client import Dispatch
    d = Dispatch("WbemScripting.SWbemLocator")
    ProvideConstants(d)

    print d._constants.wbemImpersonationLevelAnonymous
    print d._constants.wbemImpersonationLevelDelegate
  • Tim Golden at May 25, 2005 at 8:10 am
    [Thomas Heller]
    Tim Golden schrieb:
    [Thomas Heller]

    [... snip problems with py2exe & WMI ...]
    The OP of the thread Tim mentions here already had a
    solution, if I
    understood him correctly, and the other things that were
    suggested
    didn't work. Basically, IIUC, he did add the typelib
    wrappers from the
    'other' windows version manually to the library.zip file.

    Totally different solutions would be:
    - change Tim's wmi.py module so that it works with dynamic
    binding (no
    typelib wrappers needed)
    or
    Well, if it helps, there's a version of the WMI module
    that uses dynamic binding on my site:

    http://timgolden.me.uk/python/downloads/wmi-0.6a.py

    I've hardcoded the relevant constants (which is pretty
    much all I was using early binding for) and replaced
    any other EnsureDispatch calls with simple Dispatch.
    It may be dangerous since the constants may or may not be the same on
    different versions, at least in theory. I've appended a small module
    which allows to bind constants from the type library at runtime.
    Not much error checking, but you may get the idea. I'll
    leave providing
    a proper patch for pywin32, if it makes sense, to those that
    have more
    time ;-)
    OK. I've uploaded a version 0.6b to my site:

    http://timgolden.me.uk/python/downloads/wmi-0.6b.py

    which uses Thomas' ProvideConstants class and dynamic
    dispatch throughout. Testers welcome!

    TJG

    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 24, '05 at 1:50p
activeMay 25, '05 at 8:10a
posts6
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase