把python程序打包成window上能运行的exe文件
业务的程序mian.py(业务代码省略)
import os
from nicegui import ui, events, app
urllib3.disable_warnings()
xxxxx
编译文件编写(build.py)
import os
import subprocess
from pathlib import Path
import nicegui
cmd = ['PyInstaller',
'main.py', # your main file with ui.run()
'--name', 'EulerCoplit_upload', # name of your app
'--icon', './favicon.ico', # icon of your app
'--onefile',
'--windowed',
'--clean',
'--add-data', f'{Path(nicegui.__file__).parent}{os.pathsep}nicegui' # 这个是把一些数据的目录加入进来
]
subprocess.call(cmd)
注意 :编译的时候要停止运行,提前把ico文件放到同级目录下
编译
安装编译软件
pip install PyInstaller
python build.py