Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hiding console with program compiled in PY2EXE

1 view
Skip to first unread message

Marc

unread,
Dec 19, 2003, 1:34:26 AM12/19/03
to
Hi all,

I know that to hide a console normally you simply change the extension
from .py to .pyw. That's simple enough. However I can't seem to
accomplish the same thing after freezing the program. I've tried
building the setup file with the python script as a .pyw file, but it
crashes and doesn't give me a reason. This is of course because the
debug window doesn't open, so you don't know what happened (ahh, the
irony).

Does anyone know how to successfully freeze a program with py2exe?

Many thanks,
Marc

duikboot

unread,
Dec 19, 2003, 3:24:33 AM12/19/03
to
# setup.py
from distutils.core import setup
import py2exe

setup(name="convertdpi",
scripts=["convertdpi.pyw"],
)


From the dos command prompt:
c:\python23> python.exe setup.py py2exe

This works for me.

Hope it helps,

Arjen
"Marc" <mnat...@airmail.net> schreef in bericht
news:4378fa6f.03121...@posting.google.com...

Jørgen Cederberg

unread,
Dec 19, 2003, 3:43:12 AM12/19/03
to
duikboot wrote:
> # setup.py
> from distutils.core import setup
> import py2exe
>
> setup(name="convertdpi",
> scripts=["convertdpi.pyw"],
> )
>
>
> From the dos command prompt:
> c:\python23> python.exe setup.py py2exe

Hi

or instead

# setup.py
from distutils.core import setup
import py2exe
setup(name="convertdpi",

scripts=["convertdpi.py"],
)

c:\python23> python.exe setup.py py2exe -w

Which works for me :)

All options are described on http://starship.python.net/crew/theller/py2exe/

Regards
Jorgen

Pieter Claerhout

unread,
Dec 19, 2003, 3:17:48 AM12/19/03
to pytho...@python.org
Specify the -windows option in the py2exe command line. Example:

python setup.py py2exe --windows

By default, if the script ends with .pyw, it will create a console-less GUI
app. If it ends with .py, it will create a console application. By using the
--console or --windows flags, you can control this behaviour.

What I normally do to freeze a program this way is the following:

1. I create an executable using the --console option.

2. Run it on a computer that doesn't have Python installed to make sure
every required part is present. If not, adjust and go back to step 1.

3. After the program is working fine, I run py2exe using the --windows
option to create the console-less GUI app.

4. Test it again.

It might be handy to wrap the main function of your application in a
try/except statement and redirect the traceback to a file so that you know
what went wrong if you run the application without the console window.

Cheers,


pieter


-----Original Message-----
From: mnat...@airmail.net [mailto:mnat...@airmail.net]
Sent: 19 December 2003 07:34
To: pytho...@python.org
Subject: Hiding console with program compiled in PY2EXE


Hi all,

I know that to hide a console normally you simply change the extension
from .py to .pyw. That's simple enough. However I can't seem to
accomplish the same thing after freezing the program. I've tried
building the setup file with the python script as a .pyw file, but it
crashes and doesn't give me a reason. This is of course because the
debug window doesn't open, so you don't know what happened (ahh, the
irony).

Does anyone know how to successfully freeze a program with py2exe?

Many thanks,
Marc
--
http://mail.python.org/mailman/listinfo/python-list

Anand Pillai

unread,
Dec 19, 2003, 6:18:02 AM12/19/03
to
The way to prevent a py2exe program from throwing up
a console is to pass the '--windows' option to it.

i.e change your py2exe command line from

%python setup.py py2exe

to

%python setup.py py2exe --windows

HTH.

-Anand

mnat...@airmail.net (Marc) wrote in message news:<4378fa6f.03121...@posting.google.com>...

Marc

unread,
Dec 19, 2003, 5:47:39 PM12/19/03
to
Thanks to all the replies. I tried it using the --windows option, but
I get the same problem. However I'm also increasing the difficulty a
little bit by using COM with py2exe.

Here's my setup file:

# setup.py
from distutils.core import setup
import py2exe

setup(name="CCT",
scripts=["CCT.py"],
)


Here's the command I use to initiate the process:

python setup.py py2exe --progid "Excel.Application" --windows

It appears to compile successfully, but I get the same problem as I
did when inserted my program with the .pyw option. It starts to open,
then dies.

Does adding other options, such as COM, interfere with this process?
Does COM need the window for some reason?

Thanks,
Marc

Marc

unread,
Dec 19, 2003, 8:34:03 PM12/19/03
to
Update!

Silly me. I had a problem further upstream that was causing it to
fail. It has nothing to do with the COM interaction. Works perfect
now!

Thanks again,
Marc

0 new messages