gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:24:11 24 4
gpt4 key购买 nike

我创建了一个 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

最佳答案

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

BUILD_DIR/path_to_file/somefile.txt

DEST_DIR/somefile.txt

其中 dest dir 还包含 {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],

关于python - 如何在 cxfreeze 安装程序中包含子目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23537459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com