gpt4 book ai didi

python - py2exe - 生成单个可执行文件

转载 作者:IT老高 更新时间:2023-10-28 12:30:04 28 4
gpt4 key购买 nike

我以为我听说了 py2exe能够做到这一点,但我从来没有想通。有没有人成功做到这一点?我可以看看你的 setup.py 文件,以及你使用了哪些命令行选项吗?

基本上我正在考虑它给我一个可执行文件,该文件执行诸如将自身解压缩到/temp 并运行之类的操作。

最佳答案

使用 py2exe 的方法是在 setup.py 文件中使用 bundle_files 选项。对于单个文件,您需要将 bundle_files 设置为 1,compressed 设置为 True,并将 zipfile 选项设置为 None。这样,它会创建一个压缩文件以便于分发。

这里是直接从 py2exe site 中引用的 bundle_file 选项的更完整描述。 *

Using "bundle_files" and "zipfile"

An easier (and better) way to create single-file executables is to set bundle_files to 1 or 2, and to set zipfile to None. This approach does not require extracting files to a temporary location, which provides much faster program startup.

Valid values for bundle_files are:

  • 3 (default) don't bundle
  • 2 bundle everything but the Python interpreter
  • 1 bundle everything, including the Python interpreter

If zipfile is set to None, the files will be bundle within the executable instead of library.zip.

这是一个示例 setup.py:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

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

关于python - py2exe - 生成单个可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/112698/

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