How to get py2exe to build in copyright information
Asked Answered
P

5

7

I am using Py2exe to create a Windows .exe from my Python script. I would like to have the copyright information as well as the product version, description, etc. I've been able to get everything to show (in the Properties > Details of the exe), except for the copyright information. I've tried the following with no success:

from distutils.core import setup
import py2exe
import sys

if len(sys.argv) == 1:
    sys.argv.append("py2exe")
    sys.argv.append("-q")

class Target:
    def __init__(self, **kw):
        self.__dict__.update(kw)
        # for the versioninfo resources
        self.version = "1.0.0.0"
        self.company_name = "ACME."
        self.copyright = "Copyright (c) 2014 ACME."
        self.name = "My Program"

# create an instance of class Target
# and give it additional needed info
target = Target(
    description = "Test Description",
    # this is your code file
    script = "Main.py",
    # this will form TestProgram.exe
    dest_base = "TestProgram")

setup(
    options = {'py2exe': {'bundle_files': 1,
                          'compressed': 1}},
    console = [{'script': "Main.py"}],
    zipfile = None,
)

When using this method I get the File Description, Product Name, and Product version in the PROPERTIES > DETAILS of the .exe but I am missing the copyright.

Preterite answered 13/3, 2014 at 20:22 Comment(0)
P
6

I got the following to work. I realized I didn't set the target right. Fixed at the bottom where I did console = [target].

from distutils.core import setup
import py2exe
import sys

if len(sys.argv) == 1:
    sys.argv.append("py2exe")
    sys.argv.append("-q")

class Target:
    def __init__(self, **kw):
        self.__dict__.update(kw)
        self.version = "1.0.0.0"
        self.company_name = "ACME."
        self.copyright = "Copyright (c) 2014 ACME."
        self.name = "My Program"

target = Target(
    description = "Test Description",
    script = "Main.py",
    dest_base = "TestProgram")

setup(
    options = {'py2exe': {'bundle_files': 1,
                          'compressed': True}},
    zipfile = None,
    console = [target]
)
Preterite answered 13/3, 2014 at 21:44 Comment(0)
B
3

user2643864's answer is more complicated than it needs to be. jgritty's answer is nearly there, and only needs simple modification, adding a couple of entries in the dictionary assigned to console:

from distutils.core import setup
import py2exe

setup(
    options = {'py2exe': {'bundle_files': 1,
                          'compressed': 1}},
    console = [{
        'script': 'Main.py',
        'copyright': 'Copyright (C) 2016 ACME Pty Ltd',
        'company_name': 'ACME Pty Ltd',
    }],
    zipfile = None,
    version = '1.0.0.0',
    name = 'My Program',
    description = 'Test Description',
)
Blearyeyed answered 31/5, 2016 at 8:18 Comment(0)
O
1

I think there's something really wrong with your code, because it doesn't update the File Description, Product Name, and Product version in the exe. However, this code does:

from distutils.core import setup
import py2exe

setup(
    options = {'py2exe': {'bundle_files': 1,
                          'compressed': 1}},
    console = [{'script': "Main.py"}],
    zipfile = None,
    version = "1.0.0.0",
    name = "My Program",
    description = "Test Description",
)

To put the company name and copyright info into the executable is more challenging, and unfortunately, I don't know how to do that yet. This might be useful.

Outflow answered 13/3, 2014 at 21:10 Comment(2)
Ya, there was something wrong with my code. I figured it out and will post the answer. I also tried what you supplied in your answer, but the copyright information would never display. Only the description, name and version would display (even if copyright was specified).Preterite
I'm interested to see the answer.Outflow
O
0

Updated for 2023. There is a new freeze API that is the new way to compile your code. I found it was the only reliable way I could get the copyright and product version to appear using Python 3.11+.

from py2exe import freeze
 
freeze(
   console = [myservice],
   zipfile = None,
   options = {'bundle_files': 3,'compressed': 1},
   version_info={
      'version':'1.0.0',
      'product_version':'03012023',
      'product_name':'My Service',
      'copyright':'Copyright 2023 My Company',
   }
)
Ordination answered 2/3, 2023 at 17:21 Comment(0)
E
0

Thanks mbokil. It's properly working for me.

INFO: py2exe is going to stop support on the setup API and recommending users to start using py2exe.freeze API to build standalone .exe file of your code.

Ephebe answered 28/6, 2023 at 10:26 Comment(1)
Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. - From ReviewKyl

© 2022 - 2024 — McMap. All rights reserved.