2025年1月15日星期三

pyqgis

1 开发环境配置


@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass83\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass83\lib
path %PATH%;C:\OSGeo4W\apps\Qt5\bin
path %PATH%;C:\OSGeo4W\apps\Python312\Scripts

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python312

set PATH=C:\Program Files\Git\bin;C:\Users\27096\AppData\Local\Programs\Microsoft VS Code;%PATH%

cmd.exe


C:\qgis_dev>python3 -c "import sys;print(sys.path)"
['', 
'C:\\aka\\my_git\\qgis_dev', 
'C:\\OSGeo4W\\bin',
'C:\\OSGeo4W\\bin\\python312.zip', 
'C:\\OSGeo4W\\apps\\grass\\grass83\\etc\\python', 
'C:\\OSGeo4W\\apps\\qgis\\python', 
'C:\\OSGeo4W\\apps\\Python312\\DLLs', 
'C:\\OSGeo4W\\apps\\Python312\\Lib', 
'C:\\OSGeo4W\\apps\\Python312', 
'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages', 'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages\\win32', 'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages\\win32\\lib', 'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages\\Pythonwin'
]
上面的列表为了美观,顺序调整过,下面是原始输出:
[
'', 
'C:\\OSGeo4W\\apps\\grass\\grass83\\etc\\python', 
'C:\\aka\\my_git\\qgis_dev', 
'C:\\OSGeo4W\\apps\\qgis\\python', 
'C:\\OSGeo4W\\bin\\python312.zip', 
'C:\\OSGeo4W\\apps\\Python312\\DLLs', 
'C:\\OSGeo4W\\apps\\Python312\\Lib', 
'C:\\OSGeo4W\\bin', 
'C:\\OSGeo4W\\apps\\Python312',
 'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages', 'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages\\win32', 'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages\\win32\\lib', 'C:\\OSGeo4W\\apps\\Python312\\Lib\\site-packages\\Pythonwin']

为什么存在  "C:\OSGeo4W\bin\python.exe"
这个文件有什么用?

  • OSGeo4W Shell ----->   C:\OSGeo4W\OSGeo4W.bat  
  • GRASS GIS 8.3.2------>  C:\OSGeo4W\bin\grass83.bat --gui
  • QGIS Desktop 3.36.3 ------>  C:\OSGeo4W\bin\qgis-bin.exe
  • Qt Designer with QGIS 3.36.3 custom widgets  ----> C:\OSGeo4W\bin\bgspawn.exe "C:\OSGeo4W\bin\qgis-designer.bat"
  • Setup  ---->  C:\OSGeo4W\bin\bgspawn.exe "C:\OSGeo4W\bin\setup.bat"
  • SAGA GIS 9.3.1  ---->  C:\OSGeo4W\bin\bgspawn.exe "C:\OSGeo4W\bin\saga_gui.bat"
uses bgspawn to the batch jobs, which has the advantage that there is no command line window flashing up when a desktop application starts.

没有评论: