使用Pycharm软件进行对网页的打包
步骤1:创建一个main.py
代码内容如下:
import webview
import os
import sys
def resource_path(relative_path):
"""获取打包后资源的绝对路径"""
if hasattr(sys, '_MEIPASS'):
base_path = sys._MEIPASS
else:
base_path = os.path.dirname(os.path.abspath(__file__))
return os.path.join(base_path, relative_path)
if __name__ == '__main__':
html_path = resource_path('index.html')
webview.create_window('我的应用', 'file://' + html_path)
webview.start()
将html网页文件与main.py文件放到同级目录下
步骤2:创建能够运行main.py的环境
自己根据所需要的库创建环境即可,例如 pip install 库名
步骤3:终端运行指令
pyinstaller --onefile --noconsole --clean main.py
会在当前路径下,出现build、dist文件夹,spec文件。
打包的exe文件就在dist文件夹下