gpt4 book ai didi

python - 编译我编写为 .exe 和 .app 的 python 脚本

转载 作者:行者123 更新时间:2023-12-01 05:44:26 26 4
gpt4 key购买 nike

前言,我对Python的了解很少,所以最简单的解决方案可能是最好的。

本质上,我编写了一个程序,它接受用户输入并将其写入文本文件。我用 Qt 和 PySide 创建了一个 GUI。我现在想做的是将所有内容编译成一个 .exe 文件,我可以将其交给任何想要使用它的人。基本上,它需要能够在一台计算机上运行 1 个单独的 .exe 文件,而该计算机不一定安装了我所安装的任何 python 库。

该程序唯一的导入是

import sys
from PySide.QtCore import *
from PySide.QtGui import *
from math import *

以防这些对编译很重要。谢谢您的帮助,我很感激。

附注这是给我祖母的,她对计算机几乎一无所知。如果可能的话,如果它能……打开那就太棒了。我不介意它是否必须在 cmd 中运行某些东西来安装所有 python 东西,只要程序运行的 .exe 仍然只是一个 .exe。

最佳答案

我怀疑你的祖母使用 Windows,在这种情况下我建议使用 py2exe。这可能是您所需要的一切......1)。创建以下脚本并将其最后一行修改为实际脚本的名称(参见其最后一行)

#execmaker.py would be the name of this file
#stable version
from distutils.core import setup
import py2exe

includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll']

setup(
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 3,#dont bundle else unstable
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
windows=['My_Script.py'] #this is the name of your actual script
)

2).然后你可以通过cmd进入这个脚本和你的实际脚本所在的目录,然后输入

python execmaker.py py2exe

您现在应该有一个有效的可执行文件。现在,您可以双击可执行文件,您的脚本将运行。哦,是的,如果您有疑问,请按照这个人的指示进行操作...他很好!

http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/

关于python - 编译我编写为 .exe 和 .app 的 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16575384/

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