python py2exe一次编译两个py文件到两个单独的exe文件

时间:2013-10-24 13:03:44

标签: python py2exe

我正在使用此安装脚本将一个py文件编译为exe。

# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
import sys 

import os
dataFiles = []

sampleDir = r'.\\lang'
for root, dirs, files in os.walk(sampleDir):
    sampleList = []
    if files:
        for filename in files:
            #ignore SVN dirs
            if ".svn" not in root:
                sampleList.append(os.path.join(root, filename))
        if sampleList:
            dataFiles.append((root, sampleList))                                              

class Target:
       def __init__(self, **kw):
           self.__dict__.update(kw)
           self.version = "1.5.5.000"
           self.company_name = "company"
           self.copyright = 'Copyright (c) '
target = Target(
       script = "script.py",
       icon_resources=[(1, 'ico.ico')],
       )




setup(
    name = 'PROGNAME',
    author='me',
    author_email='me@me.com', 
    description = 'desc',

    windows = [target],

    options = {
                  'py2exe': {
                      'packages': 'encodings, kinterbasdb',
                      'includes': 'cairo, pango, pangocairo, atk, gobject, gio, glib, gtk',               
                  }
              },

    data_files=dataFiles,
)

但现在我有两个py文件,我想立即编译它,但每个文件应该有:

  • 不同的程序名称(当我右键单击属性中的程序时)
  • 不同的文件名
  • 不同的文件版本
  • 不同的文件图标

如何更改我的设置脚本以便能够立即执行此操作?

1 个答案:

答案 0 :(得分:1)

我发现了怎么做!希望这对每个人都有帮助:

# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
import sys    

import os
dataFiles = []

sampleDir = r'.\\lang'
for root, dirs, files in os.walk(sampleDir):
    sampleList = []
    if files:
        for filename in files:
            #ignore SVN dirs
            if ".svn" not in root:
                sampleList.append(os.path.join(root, filename))
        if sampleList:
            dataFiles.append((root, sampleList))                                                

class Target:
       def __init__(self, **kw):
           self.__dict__.update(kw)

target = Target(
       script = "script.py",
       icon_resources=[(1, 'ico.ico')],
       version = "1.5.5.000",
       company_name = "company",
       copyright = 'Copyright (c) ',
       name = 'PROGNAME',
       )

target2 = Target(
       script = "script2.py",
       icon_resources=[(1, 'ico.ico')],
       version = "1.0.0.000",
       company_name = "company",
       copyright = 'Copyright (c) ',
       name = 'SECOND PROGNAME',
       )


setup(
    author='me',
    author_email='me@me.com', 
    description = 'desc',

    windows = [target, target2],

    options = {
                  'py2exe': {
                      'packages': 'encodings, kinterbasdb',
                      'includes': 'cairo, pango, pangocairo, atk, gobject, gio, glib, gtk',               
                  }
              },

    data_files=dataFiles,
)