- pip install pyinstaller
- python run.py --build=all , 写了一个脚本,打包 Django + GUI + run.py
- 运行 dist/run.exe
import os
import sysimport argparsedjangoProgramPath = "./manage/manage.exe"
guiProgramPath = "./excel_gui.exe"def buildDjango():os.system("pyi-makespec -D manage.py")os.system("pyinstaller manage.spec --noconfirm")def buildGUI():os.system("pyinstaller -w -F excel_gui.py")def buildRun():os.system("pyinstaller -w -F run.py")def kill():# kill beforeprogramPath = [djangoProgramPath,guiProgramPath]for x in programPath:os.system(f"powershell.exe taskkill /f /im {os.path.basename(x)}")def start():kill()# 使用 power-shell 来启动,防止程序退出后,Django 也退出了# ArgumentList 是运行程序时,要传递的参数,多个用空格隔开# Start-Process -WindowStyle hidden -FilePath "./manage/manage.exe" -ArgumentList "runserver --noreload"os.system(f"powershell.exe Start-Process -WindowStyle hidden -FilePath '{djangoProgramPath}' -ArgumentList 'runserver --noreload'")os.system(f"powershell.exe {guiProgramPath}")sys.exit()def main():parser = argparse.ArgumentParser(usage="it's usage tip.", description="help info.")parser.add_argument("--build", default="", help="build py to exe.", dest="build")args = parser.parse_args()# print(args)# print(args.build)if args.build =="all":print("build~~~~")kill()buildDjango()buildGUI()buildRun()else:print("run~~~~")start()if __name__ == '__main__':main()