精简版:

如何从Python脚本而不是从终端使用PyInstaller?

我需要在Python脚本中编写什么才能等效于在终端中编写此脚本:

>python -m PyInstaller --noconsole --name WorkLogger ../WorkLogger/main.py




长版:

我使用的库要求使用PyInstaller分发可执行文件。但是我必须运行一次PyInstaller,然后更改规格文件,然后通过PyInstaller运行规格文件。

因此,在终端中,我会这样做:

>python -m PyInstaller --noconsole --name WorkLogger ../WorkLogger/main.py


运行完之后,我手动更改规格文件。然后我运行:

>python -m PyInstaller WorkLogger.spec


我编写了一个脚本,该脚本通过运行

>change_spec.py


但是我最终希望在一个Python脚本中完成所有这些工作。我希望能够输入如下内容:

>distribute_python_project.py ./Worklogger


这意味着我的Python脚本需要看起来像这样:

#Psuedocode:
#python -m PyInstaller --noconsole --name WorkLogger ../WorkLogger/main.py
#Code from change_spec.py
#python -m PyInstaller WorkLogger.spec


但是我不知道如何从python脚本而不是从终端使用PyInstaller。这可能吗? (对于那些感兴趣的人,我使用的图书馆是Kivy)。

最佳答案

感谢员工和Canh!概念工作证明:

终奌站:

>python -m PyInstaller --noconsole --name WorkLogger ../WorkLogger/main.py


Python脚本:

subprocess.call(r"python -m PyInstaller --noconsole --name WorkLogger F:\KivyApps\WorkLogger\main.py")


如果需要,可以从特定的工作目录启动子流程:

subprocess.call(r"python -m PyInstaller --noconsole --name WorkLogger F:\KivyApps\WorkLogger\main.py", cwd=r"F:\KivyApps\WorkLogger_Dist")

10-02 04:08
查看更多