By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

setting icon using py2exe?

P: n/a
I'm trying in vain to set the icon for the executable generated
by py2exe. According to various sources there are two answers:

1) Do it on the command line:

python setup.py py2exe --icon foo.ico

That generates a usage error:

error: --icon not recognized

2) According to http://starship.python.net/crew/thel...gi/CustomIcons
you can set the icon_resources in the setup.py like this:

# setup.py
from distutils.core import setup
import py2exe
setup(windows=[{"script":"vfcupdate.py","icon_resources":[(1,"rivatek.ico")]}])

That doesn't work either:

running py2exe
[...]
copying C:\Python23\Lib\site-packages\wx\wxmsw251h_html_vc.dll -> C:\cygwin\home\admin\othertools\dist
copying C:\Python23\Lib\site-packages\wx\wxbase251h_vc.dll -> C:\cygwin\home\admin\othertools\dist
copying C:\PYTHON23\w9xpopen.exe -> C:\cygwin\home\admin\othertools\dist
copying C:\WINDOWS\SYSTEM\python23.dll -> C:\cygwin\home\admin\othertools\dist
copying C:\Python23\Lib\site-packages\py2exe\run_w.exe -> C:\cygwin\home\admin\othertools\dist\vfcupdate.exe
Traceback (most recent call last):
File "setup.py", line 5, in ?
setup(windows=[{"script":"vfcupdate.py","icon_resources":[(1,"rivatek.ico")]}])
File "C:\PYTHON23\lib\distutils\core.py", line 149, in setup
dist.run_commands()
File "C:\PYTHON23\lib\distutils\dist.py", line 907, in run_commands
self.run_command(cmd)
File "C:\PYTHON23\lib\distutils\dist.py", line 927, in run_command
cmd_obj.run()
File "C:\Python23\Lib\site-packages\py2exe\build_exe.py", line 197, in run
self.create_binaries(py_files, extensions, dlls)
File "C:\Python23\Lib\site-packages\py2exe\build_exe.py", line 395, in create_binaries
arcname, target.script)
File "C:\Python23\Lib\site-packages\py2exe\build_exe.py", line 577, in build_executable
add_icon(unicode(exe_path), unicode(ico_filename), ico_id)
RuntimeError: MapExistingFile: The handle is invalid.
Has anybody really been able to set the icon for the executable
generated by py2exe?

--
Grant Edwards grante Yow! Now I'm concentrating
at on a specific tank battle
visi.com toward the end of World
War II!
Jul 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
> 2) According to http://starship.python.net/crew/thel...gi/CustomIcons
you can set the icon_resources in the setup.py like this:

# setup.py
from distutils.core import setup
import py2exe
setup(windows=[{"script":"vfcupdate.py","icon_resources":[(1,"rivatek.ico")]}])

That doesn't work either: File "C:\Python23\Lib\site-packages\py2exe\build_exe.py", line 577, in build_executable
add_icon(unicode(exe_path), unicode(ico_filename), ico_id)
RuntimeError: MapExistingFile: The handle is invalid.


Never mind....

Further googling reveals this is a known bug when running under
Win98/Me:

http://groups.google.com/groups?th=4d594c535345b98b

--
Grant Edwards grante Yow! Four thousand
at different MAGNATES, MOGULS
visi.com & NABOBS are romping in my
gothic solarium!!
Jul 18 '05 #2

P: n/a
Grant Edwards <gr****@visi.com> wrote in
news:sl*******************@grante.rivatek.com:
I'm trying in vain to set the icon for the executable generated
by py2exe. According to various sources there are two answers:

1) Do it on the command line:

python setup.py py2exe --icon foo.ico

That generates a usage error:

error: --icon not recognized
that is for versions < 0.4
it is not longer supported in 0.5+
2) According to
http://starship.python.net/crew/thel...gi/CustomIcons
you can set the icon_resources in the setup.py like this:

# setup.py
from distutils.core import setup
import py2exe
setup(windows=[{"script":"vfcupdate.py","icon_resources":[(1,"riv
atek.ico")]}]) .... RuntimeError: MapExistingFile: The handle is invalid.

Has anybody really been able to set the icon for the executable
generated by py2exe?


yes, works fine here:
windows = [
{ 'script': "hexedit_wx.py", 'icon_resources': [(0x0004,
'bigicon.ico')]},
],

i was told that the ID does not matter that much, it will just take the
first icon resource. i somewhere saw the use of 4, so i tested with that
number and since it worked for me, i didn't change it

chris

--
Chris <cl******@gmx.net>

Jul 18 '05 #3

P: n/a
I think you have to have win32all/pywin32 installed to do
resource/icon handling.

This works fine for me on Windows 98SE/XP/2000:

setup(
windows = [
{
"script": "hellow.py",
"icon_resources": [(1, "hellow.ico")]
}
],
)

If you can't get this to work, you could just include the .ico file
using data_files=["hellow.ico"], and then create the shortcuts,
pointing to the icon, using your install program, e.g. InnoSetup
(kinda like I do under Linux).
Jul 18 '05 #4

P: n/a
Grant Edwards <gr****@visi.com> writes:
2) According to http://starship.python.net/crew/thel...gi/CustomIcons
you can set the icon_resources in the setup.py like this:

# setup.py
from distutils.core import setup
import py2exe
setup(windows=[{"script":"vfcupdate.py","icon_resources":[(1,"rivatek.ico")]}])

That doesn't work either:

File "C:\Python23\Lib\site-packages\py2exe\build_exe.py", line 577, in build_executable
add_icon(unicode(exe_path), unicode(ico_filename), ico_id)
RuntimeError: MapExistingFile: The handle is invalid.


Never mind....

Further googling reveals this is a known bug when running under
Win98/Me:

http://groups.google.com/groups?th=4d594c535345b98b


The bug should be fixed in CVS. Since py2exe now can also be built with
MingW32, you could try that, even if you don't have MSVC. Or you have
to wait for the release.

Thomas
Jul 18 '05 #5

P: n/a
On 2004-06-30, simo <si************@yahoo.co.uk> wrote:
I think you have to have win32all/pywin32 installed to do
resource/icon handling.
I do.
This works fine for me on Windows 98SE/XP/2000:
Are you sure it works on 98SE? Others have reported it only
works on NT/2K/XP.
setup(
windows = [
{
"script": "hellow.py",
"icon_resources": [(1, "hellow.ico")]
}
],
)

If you can't get this to work, you could just include the .ico file
using data_files=["hellow.ico"], and then create the shortcuts,
pointing to the icon, using your install program, e.g. InnoSetup
(kinda like I do under Linux).


I've done that. The desktop icon and start menu icon are set
by InnoSetup, but the icon doesn't show up in the window banner
or in the task bar. I was assuming that setting the icon
resource in the executable would fix that.

--
Grant Edwards grante Yow! I'm having fun
at HITCHHIKING to CINCINNATI
visi.com or FAR ROCKAWAY!!
Jul 18 '05 #6

P: n/a
On 2004-06-30, Thomas Heller <th*****@python.net> wrote:
Never mind....

Further googling reveals this is a known bug when running under
Win98/Me:

http://groups.google.com/groups?th=4d594c535345b98b


The bug should be fixed in CVS. Since py2exe now can also be built with
MingW32, you could try that, even if you don't have MSVC. Or you have
to wait for the release.


Thanks! If I run out of things to do, I'll install MingW32 and
try to build the CVS code. Otherwise I'll wait for the next
release.

--
Grant Edwards grante Yow! It was a JOKE!! Get
at it?? I was receiving
visi.com messages from DAVID
LETTERMAN!! YOW!!
Jul 18 '05 #7

P: n/a
Grant Edwards wrote:
On 2004-06-30, Thomas Heller <th*****@python.net> wrote:

Never mind....

Further googling reveals this is a known bug when running under
Win98/Me:

http://groups.google.com/groups?th=4d594c535345b98b


The bug should be fixed in CVS. Since py2exe now can also be built with
MingW32, you could try that, even if you don't have MSVC. Or you have
to wait for the release.

Thanks! If I run out of things to do, I'll install MingW32 and
try to build the CVS code. Otherwise I'll wait for the next
release.

Or if you don't have time for that you could try this build which is
from latest CVS:
http://davidf.sjsoft.com/files/py2ex...in32-py2.3.exe

Untested :-)
David
Jul 18 '05 #8

P: n/a
On 2004-06-30, David Fraser <da****@sjsoft.com> wrote:
Or if you don't have time for that you could try this build
which is from latest CVS:
http://davidf.sjsoft.com/files/py2ex...in32-py2.3.exe

Untested :-)


Tested (at least a little bit), and it appears to work.

Thanks!

The correct icons show up in the desktop explorer (which is
new), but I still don't get my icons showing up in the window's
banner or in the taskbar when the program is running. :/

--
Grant Edwards grante Yow! Kids, don't gross me
at off... "Adventures with
visi.com MENTAL HYGIENE" can be
carried too FAR!
Jul 18 '05 #9

P: n/a
On 2004-07-01, Grant Edwards <gr****@visi.com> wrote:
The correct icons show up in the desktop explorer (which is
new), but I still don't get my icons showing up in the window's
banner or in the taskbar when the program is running. :/


I guess you have to set that at runtime. I had thought that if
the .exe file had icon resources, Windows would use them by
default, but I guess not. [In wxPython you call the SetIcon()
method of the top-level frame.]

--
Grant Edwards grante Yow! I hope something GOOD
at came in the mail today so
visi.com I have a REASON to live!!
Jul 18 '05 #10

P: n/a
Grant Edwards <gr****@visi.com> wrote:

[snip]
This works fine for me on Windows 98SE/XP/2000:
Are you sure it works on 98SE? Others have reported it only
works on NT/2K/XP.
Well I don't know about *building* in 98SE (I only use 2000/XP for
development) but the resulting binary certainly incorporates the icon
in 98SE/NT4/2000/XP.

[...] If you can't get this to work, you could just include the .ico file
using data_files=["hellow.ico"], and then create the shortcuts,
pointing to the icon, using your install program, e.g. InnoSetup
(kinda like I do under Linux).

I've done that. The desktop icon and start menu icon are set
by InnoSetup, but the icon doesn't show up in the window banner
or in the task bar. I was assuming that setting the icon
resource in the executable would fix that.


No, you have to set the icon from wxPython for the TaskBar and window
icon, py2exe only fixes the *executable's* icon (in Explorer).

In your mainWindow(wx.Frame) do:

self.icon = wx.Icon("hellow.ico", wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)

This works on Linux too (for window and Panel), which I was quite
pleased with, especially as I didn't even do an XPM version, just the
ICO file....
Jul 18 '05 #11

P: n/a
On 2004-07-01, simo <si************@yahoo.co.uk> wrote:
I've done that. The desktop icon and start menu icon are set
by InnoSetup, but the icon doesn't show up in the window
banner or in the task bar. I was assuming that setting the
icon resource in the executable would fix that.
No, you have to set the icon from wxPython for the TaskBar and
window icon, py2exe only fixes the *executable's* icon (in
Explorer).


It seems odd that by default Windows won't use the executable's
icon for its window. But, a lot of things in Windows seem odd
to me...
In your mainWindow(wx.Frame) do:

self.icon = wx.Icon("hellow.ico", wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)
Yup, that does it.
This works on Linux too (for window and Panel), which I was
quite pleased with, especially as I didn't even do an XPM
version, just the ICO file....


That's cool! It didn't even occur to me to try to use the .ico
file under Linux.

--
Grant Edwards grante Yow! "DARK SHADOWS"
at is on!! Hey, I think
visi.com the VAMPIRE forgot his
UMBRELLA!!
Jul 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.