furkantokac
furkantokac

Reputation: 311

.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

Upvotes: 4

Views: 5567

Answers (5)

Chud37
Chud37

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

Ronan Paixão
Ronan Paixão

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

Taylor Huang
Taylor Huang

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

furkantokac
furkantokac

Reputation: 311

I handled my problem like that;

  1. I used the above code which I post in my question.
  2. Then I installed Resourch Hacker program.
  3. I opened myprogram.exe file with Resourch Hacker program.
  4. Then Action > Replace Icon > I choosed the icon which I want.
  5. And its ok!

For Resourch Hacker tutorial CLICK THIS

Upvotes: 2

jatinkumar patel
jatinkumar patel

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

Related Questions