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

标签 python pyinstaller

简短版本:

如何从 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)。

最佳答案

Berniiii 的回答是正确的,但没有切中要点,我个人觉得它有点令人困惑。

这是官方文档的答案:running-pyinstaller-from-python-code

import PyInstaller.__main__

PyInstaller.__main__.run([
    'my_script.py',
    '--onefile',
    '--windowed'
])

相当于:

pyinstaller my_script.py --onefile --windowed

关于python - 如何从脚本而不是终端使用 PyInstaller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52636686/

相关文章:

python - pyinstaller生成的exe文件不能在别人的电脑上使用

python - Pyinstaller EXE 在启动时崩溃

python - PyInstaller - 导入错误 : No module named _bootlocale

python - Django ModelForm 无法使用 ModelForm 和 save_m2m 保存 "many to many"记录

python - ValueError : Buffer dtype mismatch, 预期 'double' 但得到 'float'

python - pip 不安装模块

pyinstaller - 如何在 pyinstaller 中包含 wkhtmltopdf

python - Scikit Learn SGDClassifier Partial_Fit 错误

python - 计算字符串中的连续字符

linux - 在 virtual_env 中使用 pyinstaller 时出现 win32com 错误