473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

setting icon using py2exe?

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
11 15712
> 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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Haim Ashkenazi | last post by:
Hi I'm trying to build a binary with py2exe. I've used the method suggested in the py2exe wiki about adding icon resources to apps. it build ok on win2k, but when I try to build the same on...
1
by: sarmin kho | last post by:
Hi Pythoners, i remember that i saw posting about changing the icon of a python executable but i kind of lost where to find the posting... basically, this is my first time using the py2exe to...
2
by: Joe Wong | last post by:
Hi, I have encountered an error whenever I put the "icon_resources" line in my setup.py file: from distutils.core import setup import py2exe setup(
1
by: hansolox1 | last post by:
The following program simply sets the icon of a form called form1. When I get the name of the embedded icon using GetManifestResourceNames(), I store the name in a string variable called s. The...
0
by: Vyz | last post by:
I have given icon like this to main frame of my program ib=wx.IconBundle() ib.AddIconFromFile("SriPadma.ico",wx.BITMAP_TYPE_ANY) self.SetIcons(ib and then I have made binary with py2exe and in...
2
by: Martin | last post by:
If i create an app using py2exe/py2app is there then a way on windows/ mac to get access to a file dragged and dropped on to the .exe/.app icon? Martin
1
Plater
by: Plater | last post by:
C# (and possibly VB.NET) in VS2005 can be a bit tricky. Here's my little rundown: Add an icon file to your project (new or exisiting, whichever) Open the icon file is VS and edit as desired....
2
by: flarefight | last post by:
I have created an app using python and then converting it to an exe using py2exe, and have the following code: "icon_resources": in my py2exe setup file, the appFavicon works fine and it sets...
0
by: vishnu1986 | last post by:
Hi guys, I saw quite a few posts regarding this but I was unable to solve this problem that I am facing. First off, when I do the following in my setup.py, windows= } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.