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

B

Brian Hlubocky

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 "ImportError: 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
 
B

Brian Kelley

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

http://aspn.activestate.com/ASPN/Mail/Message/766627

The piece of magic is, I believe, "pythoncom.frozen = 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
 
B

Brian Kelley

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

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
 
T

Tony C

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 "ImportError: 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

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)
 
T

Thomas Heller

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 "ImportError: 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!

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
 
K

Kent Hsu (Hsu, Chih-Peng)

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

Best Regards,
Kent Hsu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top