Py2Exe and a simple COM Windows Program (can't import pythoncom)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Hlubocky

    Py2Exe and a simple COM Windows Program (can't import pythoncom)

    I'm have a fairly simple (in terms of COM) python program that pulls
    info from an Access database and creates Outlook contacts from that
    information. It uses wxPython for gui and works without problems.

    I want to be able to distribute this program using py2exe, but I am
    having some problems. I am using a simple setup.py like in the
    documentation for the py2exe tool and everything compiles ok, except
    that when I run the exe, I get an exception that says "ImportErro r: no
    module named pythoncom." My program used win32com (which appears to be
    loaded fine with the executable) until I needed thread support for the
    gui. In order to do this, I needed to import pythoncom and call
    CoInitialize() and CoUninitialize( ) manually for the new thread. I
    believe it is this use of the pythoncom module that py2exe is having
    trouble with.

    I tried adding "pythoncom" to the import list in the distutils
    setup.py but the py2exe tool gave me a warning that said it couldn't
    be located. I am able to import this module just fine in python
    scripts and at the interpreter. I am relatively new to COM and its use
    with python as well as with distutils and py2exe. If anyone could help
    me out with this, it would be greatly appreciated!

    Thanks,
    Brian
  • Brian Kelley

    #2
    Re: Py2Exe and a simple COM Windows Program (can't import pythoncom)

    A quick search for pythoncom and py2exe yielded this page (which I have
    actually used before so I can verify that it works):



    The piece of magic is, I believe, "pythoncom.froz en = 1" Hopefully this
    hasn't changed too much since I last used it.

    Let me know if you have troubles, I'll dig up my old scripts that I py2exe'd

    Brian

    Comment

    • Brian Kelley

      #3
      Re: Py2Exe and a simple COM Windows Program (can't import pythoncom)

      Brian Kelley wrote:[color=blue]
      > A quick search for pythoncom and py2exe yielded this page (which I have
      > actually used before so I can verify that it works):
      >[/color]

      Oops. I think I was answering the wrong question. What I sent you was
      how to py2exe a pythoncom server so I don't think that it is going to
      help. Sorry about that. I'll see if I have any more notes on py2exe
      and pythoncom.

      Brian

      Comment

      • Tony C

        #4
        Re: Py2Exe and a simple COM Windows Program (can't import pythoncom)

        hlubocky@uiuc.e du (Brian Hlubocky) wrote in message news:<982e9537. 0401071249.4d75 c8fb@posting.go ogle.com>...[color=blue]
        > I'm have a fairly simple (in terms of COM) python program that pulls
        > info from an Access database and creates Outlook contacts from that
        > information. It uses wxPython for gui and works without problems.
        >
        > I want to be able to distribute this program using py2exe, but I am
        > having some problems. I am using a simple setup.py like in the
        > documentation for the py2exe tool and everything compiles ok, except
        > that when I run the exe, I get an exception that says "ImportErro r: no
        > module named pythoncom." My program used win32com (which appears to be
        > loaded fine with the executable) until I needed thread support for the
        > gui. In order to do this, I needed to import pythoncom and call
        > CoInitialize() and CoUninitialize( ) manually for the new thread. I
        > believe it is this use of the pythoncom module that py2exe is having
        > trouble with.
        >
        > I tried adding "pythoncom" to the import list in the distutils
        > setup.py but the py2exe tool gave me a warning that said it couldn't
        > be located. I am able to import this module just fine in python
        > scripts and at the interpreter. I am relatively new to COM and its use
        > with python as well as with distutils and py2exe. If anyone could help
        > me out with this, it would be greatly appreciated!
        >
        > Thanks,
        > Brian[/color]

        Try posting a message in the PythonWin32 Mail List at ActiveState.com
        It's more specific to Windows, than generic Python.
        (I'm actually interested in this answer myself)

        Comment

        • Thomas Heller

          #5
          Re: Py2Exe and a simple COM Windows Program (can't importpythoncom )

          hlubocky@uiuc.e du (Brian Hlubocky) writes:
          [color=blue]
          > I'm have a fairly simple (in terms of COM) python program that pulls
          > info from an Access database and creates Outlook contacts from that
          > information. It uses wxPython for gui and works without problems.
          >
          > I want to be able to distribute this program using py2exe, but I am
          > having some problems. I am using a simple setup.py like in the
          > documentation for the py2exe tool and everything compiles ok, except
          > that when I run the exe, I get an exception that says "ImportErro r: no
          > module named pythoncom." My program used win32com (which appears to be
          > loaded fine with the executable) until I needed thread support for the
          > gui. In order to do this, I needed to import pythoncom and call
          > CoInitialize() and CoUninitialize( ) manually for the new thread. I
          > believe it is this use of the pythoncom module that py2exe is having
          > trouble with.
          >
          > I tried adding "pythoncom" to the import list in the distutils
          > setup.py but the py2exe tool gave me a warning that said it couldn't
          > be located. I am able to import this module just fine in python
          > scripts and at the interpreter. I am relatively new to COM and its use
          > with python as well as with distutils and py2exe. If anyone could help
          > me out with this, it would be greatly appreciated![/color]

          py2exe 0.4.x is no longer compatible with the newer win32all versions,
          you need the 0.5.0 prerelease for this (which requires Python 2.3, btw).

          No docs so far, but samples are included - you have to modify your setup
          script a little.

          Thomas

          Comment

          • Kent Hsu (Hsu, Chih-Peng)

            #6
            Re: Py2Exe and a simple COM Windows Program (can't import pythoncom)

            Just include the 'pythoncom23.dl l'. (usally can be found in
            %windir%/system32 -> Windows 2000).

            Best Regards,
            Kent Hsu

            Brian Hlubocky <hlubocky@uiuc. edu> wrote in message
            news:982e9537.0 401071249.4d75c 8fb@posting.goo gle.com...[color=blue]
            > I'm have a fairly simple (in terms of COM) python program that pulls
            > info from an Access database and creates Outlook contacts from that
            > information. It uses wxPython for gui and works without problems.
            >
            > I want to be able to distribute this program using py2exe, but I am
            > having some problems. I am using a simple setup.py like in the
            > documentation for the py2exe tool and everything compiles ok, except
            > that when I run the exe, I get an exception that says "ImportErro r: no
            > module named pythoncom." My program used win32com (which appears to be
            > loaded fine with the executable) until I needed thread support for the
            > gui. In order to do this, I needed to import pythoncom and call
            > CoInitialize() and CoUninitialize( ) manually for the new thread. I
            > believe it is this use of the pythoncom module that py2exe is having
            > trouble with.
            >
            > I tried adding "pythoncom" to the import list in the distutils
            > setup.py but the py2exe tool gave me a warning that said it couldn't
            > be located. I am able to import this module just fine in python
            > scripts and at the interpreter. I am relatively new to COM and its use
            > with python as well as with distutils and py2exe. If anyone could help
            > me out with this, it would be greatly appreciated!
            >
            > Thanks,
            > Brian[/color]


            Comment

            Working...