Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.exe Icon Doesn't Change [py2exe]

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

like image 974
furkantokac Avatar asked Dec 11 '22 00:12

furkantokac


2 Answers

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.

like image 64
Ronan Paixão Avatar answered Dec 13 '22 13:12

Ronan Paixão


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")],
            }],
)
like image 36
jatinkumar patel Avatar answered Dec 13 '22 12:12

jatinkumar patel