pyqgis 打包

命令行运行C:\OSGeo4W\bin\python-qgis-ltr.bat -m PyInstaller
如图所示安装成功。
在这里插入图片描述
3. 编写示例程序install.py

import sys,os
from qgis.core import QgsApplication
from qgis.gui import QgsMapCanvas

os.environ['GDAL\_DATA'] = r'C:\OSGeo4W\share\gdal'
os.environ['PROJ\_LIB'] = r'C:\OSGeo4W\share\proj'
def init():
  a = QgsApplication([], True)
  QgsApplication.setPrefixPath('qgis', True)
  QgsApplication.initQgis()
  return a

def show\_canvas(app):
  canvas = QgsMapCanvas()
  canvas.show()
  app.exec_()
app = init()
show_canvas(app)

命令行运行C:\OSGeo4W\bin\python-qgis-ltr.bat install.py
如下图所示:
在这里插入图片描述

  1. 编写打包install.bat
"C:\OSGeo4W\bin\python-qgis-ltr.bat" -m PyInstaller -w ^
--icon=logo.ico ^
--add-data="C:\OSGeo4W\apps\qgis-ltr\plugins;qgis\plugins" ^
--add-data="C:\OSGeo4W\apps\Python37\Lib\site-packages\PyQt5\\*.pyd;PyQt5" ^
--add-data="C:\OSGeo4W\apps\qt5\plugins\styles;PyQt5\Qt\plugins\styles" ^
--add-data="C:\OSGeo4W\apps\qt5\plugins\iconengines;PyQt5\Qt\plugins\iconengines" ^
--add-data="C:\OSGeo4W\apps\qt5\plugins\imageformats;PyQt5\Qt\plugins\imageformats" ^
--add-data="C:\OSGeo4W\apps\qt5\plugins\platforms;PyQt5\Qt\plugins\platforms" ^
--add-data="C:\OSGeo4W\apps\qt5\plugins\platformthemes;PyQt5\Qt\plugins\platformthemes" ^
install.py


解析:C:\OSGeo4W\apps\qgis-ltr\plugins -> qgis\plugins打包时将相应的文件拷贝到指定的文件夹下。

命令行在当前目录下执行install.bat
执行结果如下:
在这里插入图片描述

  1. 运行打包后的程序
    dist\install\install.exe
    在这里插入图片描述
    执行结果:
    在这里插入图片描述

注意:QgsApplication.setPrefixPath('qgis', True)指的是打包后的安装目录。
在这里插入图片描述
在这里插入图片描述

Reference

https://blog.youkuaiyun.com/this_is_id/article/details/102974721

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值