1

作为序言,我对 python 的了解很少,所以最简单的解决方案可能是最好的解决方案。

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

该程序的唯一进口是

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

如果这些对编译很重要。谢谢你的帮助,我很感激。

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

4

2 回答 2

1

下载 pyinstaller ( http://www.pyinstaller.org/ )

打开你的 cmd 提示符

cd folder
c:\pyinstaller\pyinstaller.py --noconsole --onefile my_script.py

exe应该在创建的dist文件夹中找到

于 2013-05-15T21:39:49.020 回答
1

我怀疑你的祖母使用 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/

于 2013-05-15T22:28:53.627 回答