Reputation: 311
My icon file myicon.ico in same directory with setup.py. When I run py2exe, myproject.exe doesn't have icon. I looked for solution but couldn't find.
setup.py code is:
from distutils.core import setup
import py2exe
setup(
windows=[{
"script": "myproject.py",
"icon_resources": [(0, "favicon.ico")],
}]
)
OS: Win8.1 64bit
Upvotes: 4
Views: 5567
Reputation: 5027
I used a different program, came accross pyinstaller from this post and it worked first time.
Installed it:
pip install pyinstaller
Compiled my program:
pyinstaller myprogram.py -i icon.ico
Worked first time! Hope that helps.
Upvotes: 0
Reputation: 8695
It appears py2exe has a 4-year-old bug on handling icons, but due to its description, I managed to make this workaround:
setup_dict = dict(
windows = [{'script': "script.py",
"icon_resources": [(1, "icon.ico")}],
)
setup(**setup_dict)
setup(**setup_dict)
This pretty much builds the project twice. If your project is complex and takes too long to process through py2exe, you can use this to build a dummy py file:
import tempfile
tf = tempfile.NamedTemporaryFile(delete=False)
tf.close()
setup(
windows = [{
'script': tf.name,
"icon_resources":[(1, "icon.ico")]}]
)
os.remove(tf.name)
Just don't forget to set excludes like your project, otherwise you will get your dist
folder cluttered with unwanted files.
Upvotes: 8
Reputation: 61
I meet the same problem. I have solved it by download a win7 icon from http://www.iconarchive.com/search?q=windows+7&page=5, and the reason should be the icon file that could not work at the very start is not a correct win7 format icon.
this web page https://www.creativefreedom.co.uk/icon-designers-blog/windows-7-icon-sizes/ tells us a topic "Testing your Windows 7 Icon" to check whether a icon is a really win7 icon.
Upvotes: 0
Reputation: 311
I handled my problem like that;
For Resourch Hacker tutorial CLICK THIS
Upvotes: 2
Reputation: 2990
Please try this
from distutils.core import setup
setup(
options = {'py2exe': {'bundle_files': 1}},
zipfile = None,
windows = [{
"script":"myproject.py",
"icon_resources": [(1, "favicon.ico")],
}],
)
Upvotes: 4