1

我的问题如下:我想创建一个可以创建其他可执行文件的脚本。这些新的可执行文件必须是独立的,因此它们不需要任何 DLL 等。我知道 PyInstaller 可以做到这一点,但只能通过控制台/命令行。所以本质上,我想做的是制作一个导入pyinstaller的python脚本,创建另一个.py文件并使用pyinstaller将新脚本编译为.exe,所以没有安装python的人可以使用这个程序。

编辑:脚本本身应该只使用一个文件,所以它也可以是一个文件可执行文件

4

3 回答 3

1

Supposing you have already installed Pyinstaller in PYINSTALLER_PATH (you should have called the Configure.py script in the distribution for the first time), Pyinstaller generates a spec file from your main script by calling the Makespec.py. You can add some flags to generate one dir binary distribution or one file. Finally you have to call Build.py with spec file.

This is easy scriptable with a couple of system calls. Something like :

import os

PROJECT_NAME = "test"
PROJECT_MAIN_SCRIPT = "main_script.py"
MAKESPEC_CMD = """%s %s\Makespec.py -X -n %s -F %s""" % (PYTHON_EXECUTABLE, PYINSTALLER_PATH, PROJECT_NAME, PROJECT_MAIN_SCRIPT)
BUILD_CMD = """%s %s\Build.py %s.spec""" % (PYTHON_EXECUTABLE, PYINSTALLER_PATH, PROJECT_NAME)

os.system(MAKESPEC_CMD)
os.system(BUILD_CMD)

You can avoid to generate the spec file every time and hack it, adding embedded resources (i.e. xml files or configuration) and specifying some other flag. Basically this is a python file, with the definition of some dictionaries.

I don't think there is a Pyinstaller module you can use directly, but you can look at Build.py and mimic its behaviour to do the same. Build.py is the main script which does the trick.

于 2012-04-24T23:20:14.407 回答
0

您可能想查看cx_Freeze,它可以用来做这种事情。

使用 cx_Freeze 有三种不同的方法。第一种是使用包含的 cxfreeze 脚本,它适用于简单的脚本。第二个是创建一个 distutils 设置脚本,它可以用于更复杂的配置或保留配置以备将来使用。第三种方法涉及直接使用 cx_Freeze 内部使用的类和模块,应保留用于复杂的脚本或扩展或嵌入

资源

于 2012-04-24T17:22:48.777 回答
0

尝试下载 Pyinstaller 的最新开发代码。他们在那里尝试实现用于构建可执行文件的 GUI 工具包。

于 2012-04-24T17:34:58.057 回答