通过pyinstaller 打包bottle 应用

pyinstaller 是一个很不错的python 应用打包工具,灵活简单,以下对于以前一个简单的bottle 使用pyinstaller 打包

打包命令

代码参考下边的资料

  • 参考命令
pyinstaller --add-data "static/*:static"   app.py

一些细节

因为打包运行有一些差异,尤其是使用了bottle 静态资源路径的,解决方法如下

if hasattr(sys, '_MEIPASS'):
    # 获取打包后的临时路径
    resource_path = os.path.join(sys._MEIPASS, 'static')
else:
    resource_path = os.path.join(os.path.dirname(__file__), 'static')


@route('/static/<filepath:path>')
def server_static(filepath):
    return static_file(filepath, root=resource_path)

说明

对于一些信息,pyinstaller 官方文档有详细的说明,可以详细看看,后边会介绍下pyinstaller

参考资料

https://github.com/rongfengliang/bottle_ollama_learning

https://pyinstaller.org/en/stable/

https://pyinstaller.org/en/stable/runtime-information.html

posted on 2025-02-26 08:00  荣锋亮  阅读(33)  评论(0)    收藏  举报

导航