使用cx_freeze时如何捆绑其他文件?


问题内容

我在Windows系统上使用Python 2.6和cx_Freeze 4.1.2。我已经创建了setup.py来构建我的可执行文件,并且一切正常。

当cx_Freeze运行时,它将所有内容移动到build目录中。我的目录中还包含其他文件build。我怎样才能做到这一点?这是我的结构:

src\
    setup.py
    janitor.py
    README.txt
    CHNAGELOG.txt
    helpers\
        uncompress\
            unRAR.exe
            unzip.exe

这是我的片段:

设定

( name='Janitor',
  version='1.0',
  description='Janitor',
  author='John Doe',
  author_email='john.doe@gmail.com',
  url='http://www.this-page-intentionally-left-blank.org/',
  data_files =
      [ ('helpers\uncompress', ['helpers\uncompress\unzip.exe']),
        ('helpers\uncompress', ['helpers\uncompress\unRAR.exe']),
        ('', ['README.txt'])
      ],
  executables =
      [
      Executable\
          (
          'janitor.py', #initScript
          )
      ]
)

我似乎无法使它正常工作。我需要MANIFEST.in文件吗?


问题答案:

弄清楚了。

from cx_Freeze import setup,Executable

includefiles = ['README.txt', 'CHANGELOG.txt', 'helpers\uncompress\unRAR.exe', , 'helpers\uncompress\unzip.exe']
includes = []
excludes = ['Tkinter']
packages = ['do','khh']

setup(
    name = 'myapp',
    version = '0.1',
    description = 'A general enhancement utility',
    author = 'lenin',
    author_email = 'le...@null.com',
    options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}}, 
    executables = [Executable('janitor.py')]
)

注意:

  • include_files必须包含setup.py脚本的“仅”相对路径,否则构建将失败。
  • include_files可以是字符串列表,即一堆文件及其相对路径,
    或者

  • include_files 可以是一个元组列表,其中元组的前半部分是具有绝对路径的文件名,后半部分是具有绝对路径的目标文件名。

(当缺少文档时,请咨询青蛙青蛙专家)