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
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.
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")],
}],
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With