gpt4 book ai didi

python - 如何将python脚本编译为二进制可执行文件

转载 作者:IT老高 更新时间:2023-10-28 21:07:14 26 4
gpt4 key购买 nike

我需要将 Python 脚本转换为 Windows 可执行文件。

我已将 Python 2.6 安装到 python26

我创建了一个脚本并将其保存在 C:\pythonscript 中。这个文件夹里面有两个文件

Setup.pyoldlogs.py(此文件需要覆盖)

setup.py 代码是

from distutils.core import setup
import py2exe

setup(console=['oldlogs.py'])

如何将 oldlogs.py 转换为 exe 文件?

最佳答案

或使用 PyInstaller作为py2exe 的替代品.这是一个很好的starting point . PyInstaller 还允许您为 linux 和 mac 创建可执行文件...

以下是使用 PyInstaller 解决手头问题的方法:

pyinstaller oldlogs.py

来自工具的文档:

PyInstaller analyzes myscript.py and:

  • Writes myscript.spec in the same folder as the script.
  • Creates a folder build in the same folder as the script if it does not exist.
  • Writes some log files and working files in the build folder.
  • Creates a folder dist in the same folder as the script if it does not exist.
  • Writes the myscript executable folder in the dist folder.

In the dist folder you find the bundled app you distribute to your users.

关于python - 如何将python脚本编译为二进制可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12339671/

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