如何在cxfreeze安装程序中包含子目录中的文件

时间:2014-05-08 09:10:46

标签: python packaging cx-freeze

我已经创建了一个cxfreeze_setup.py文件并运行该命令 python cxfreeze_setup.py build_exe

cxfreeze_setup.py包含:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Python 3 compatibility
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import sys
from cx_Freeze import setup, Executable

from daysgrounded.globalcfg import NAME, VERSION, DATA_FILES
from daysgrounded import (DESC, LICENSE, URL, KEYWORDS, CLASSIFIERS)

AUTHOR = 'Joao Matos'
SCRIPT = NAME + '/__main__.py'
TARGET_NAME = NAME + '.exe'

base = None
# GUI applications require a different base on Windows
if sys.platform == 'win32':
    base = 'Win32GUI'

build_exe_options = dict(compressed=True,
                         include_files=['AUTHORS.txt',
                                        'CHANGES.txt',
                                        'LICENSE.txt',
                                        'README.txt',
                                        'README.rst',
                                        NAME],
                        )

setup(name=NAME,
      version=VERSION,
      description=DESC,
      long_description=open('README.txt').read(),
      #long_description=(read('README.txt') + '\n\n' +
      #                  read('CHANGES.txt') + '\n\n' +
      #                  read('AUTHORS.txt')),
      license=LICENSE,
      url=URL,
      author=AUTHOR,
      author_email='jcrmatos@gmail.com',

      keywords=KEYWORDS,
      classifiers=CLASSIFIERS,

      executables=[Executable(script=SCRIPT,
                              base=base,
                              compress=True,
                              targetName=TARGET_NAME,
                             )],

      options=dict(build_exe=build_exe_options),
     )

构建工作但我想将NAME子目录中的* .txt文件包含在创建exe的同一目录中。 include_files只允许我包含子目录(不移动文件)。

我想要的最终结果与使用“普通”构建命令的结果相同 python setup.py sdist bdist_egg bdist_wininst bdist_wheel 使用setup.py选项完成此操作

include_package_data=True
package_data=dict(daysgrounded=['usage.txt', 'LICENSE.txt', 'banner.txt'])

和带有

的MANIFEST.in文件
include daysgrounded\banner.txt
include daysgrounded\LICENSE.txt
include daysgrounded\usage.txt

谢谢,

JM

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您需要执行以下操作。

BUILD_DIR /文件路径/ somefile.txt

dest_dir将/ somefile.txt

其中dest目录还包含{program} .exe

使用include_files尝试以下操作:

include_files = 
   [
    ('path_to_file/somefile.txt', 'somefile.txt'),
    ('path_to_file/otherfilename.txt, 'newfilename.txt)
   ]

第二行演示了如何通过更改第二个名称来重命名文件。

如果我理解上面的描述,则具体到示例:

include_files=[
    ('daysgrounded/AUTHORS.txt','AUTHORS.txt'),
    ('daysgrounded/CHANGES.txt','CHANGES.txt'),
    ('daysgrounded/LICENSE.txt','LICENSE.txt'),
    ('daysgrounded/README.txt','README.txt'),
    ('daysgrounded/README.rst','README.rst'),
    NAME],