1.在项目根目录创建my_app.spec
文件,内容如下:
# -*- mode: python ; coding: utf-8 -*-block_cipher = Nonea = Analysis(['server.py'], # flask入口pathex=[],binaries=[], datas=[("E:/**/templates","/templates"),("E:/**/static","/static")],# 将资源的绝对路径转换为你打包的exe的相对路径hiddenimports=[],hookspath=[],hooksconfig={},runtime_hooks=[],excludes=[],win_no_prefer_redirects=False,win_private_assemblies=False,cipher=block_cipher,noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)exe = EXE(pyz,a.scripts,a.binaries,a.zipfiles,a.datas,[],name='my_flask_app', #名字自己定debug=False,bootloader_ignore_signals=False,strip=False,upx=True,upx_exclude=[],runtime_tmpdir=None,console=True,disable_windowed_traceback=False,argv_emulation=False,target_arch=None,codesign_identity=None,entitlements_file=None,icon=['server.ico'], # 程序图标
)
2.开始打包
运行以下命令来使用PyInstaller
根据my_app.spec
文件打包flask应用程序:
pyinstaller my_app.spec