Python 便携式 pyinstaller

Python portable pyinstaller

我正在构建一个应用程序,我希望我的用户只需单击几下即可创建可执行文件以进行某些设置。这是一个使用 Tkinter 制作的 GUI 应用程序,其中有一个包含一些选项的页面。然后应该将这些选项写入预制的 Python 脚本。那将是没有问题的。棘手的部分是将脚本编译成可执行文件 (.exe)。我一直在使用 PyInstaller 来制作可执行文件,但那只是在我自己的本地计算机上。如果我想打包我的应用程序并捆绑 PyInstaller 怎么办?我知道 PyInstaller 需要 pywin32,这意味着它也必须捆绑。

我完全不知道如何将 PyInstaller 与我的应用程序捆绑在一起。

我一直在用谷歌搜索这个问题,但似乎根本找不到任何帮助。我得到的最接近的是 this post,但帮助不大。

尝试使用Nuitka. I tried some alternatives for Python (including PyInstaller) and like this one most. With Nuitka you can compile your script (and all modules it need) to standalone .exe file. Then you can create installer with many available options.

这里是user manual,这里是命令示例(我用于我的项目):

nuitka --standalone --recurse-all --recurse-stdlib --remove-output --windows-disable-console --recurse-directory=YOUR_PROJECT_DIR

更新: 如何 运行 脚本中的 nuitka:

import os
import subprocess

project_dir = os.path.abspath('project')
project_main = os.path.abspath('project\main.py')

subprocess.call([
    'nuitka', '--standalone', '--recurse-all', '--recurse-stdlib', '--remove-output',
    '--windows-disable-console', 
    # '--windows-icon={}'.format(icon_path),
    '--recurse-directory={}'.format(project_dir), 
    project_main
    ], shell=True)