WingPro PyQGIS setup for scripting

Can anyone guide me on their successful setup of WingPro to write code (and debug) PyQGIS? My setup: Windows 10, QGIS version is 3.12, WingPro version 7.2

running a batch file to start WingPro that looks like this:

@echo off
call "%~dp0\o4w_env.bat"
call "%OSGEO4W_ROOT%\apps\grass\grass78\etc\env.bat"
call qt5_env.bat
call py3_env.bat
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps\grass\grass78\lib;%OSGEO4W_ROOT%\apps\grass\grass78\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
start /d "C:\Program Files (x86)\Wing Pro 7.2\bin" wing.exe

My Project Python Executable is: c:\Program Files\QGIS 3.12\apps\Python37\python.exe

My Project Paths are:

C:\Program Files\QGIS 3.12\apps\Python37\DLLs;C:\Program Files\QGIS 3.12\apps\Python37\Lib;C:\Program Files\QGIS 3.12\apps\Python37;C:\Program Files\QGIS 3.12\apps\Python37\Lib\site-packages;C:\Program Files\QGIS 3.12\apps\Python37\Lib\site-packages\win32;C:\Program Files\QGIS 3.12\apps\Python37\Lib\site-packages\win32\lib;C:\Program Files\QGIS 3.12\apps\Python37\Lib\site-packages\pythonwin;C:\Program Files\QGIS 3.12\apps\qgis;C:\Program Files\QGIS 3.12\apps\qgis\python\plugin

What am I missing. I have had success writing scripts for ESRI's ArcPy in Wing but for the life of me don't seem to be able to get this to work for QGIS. Any Help would be greatly appreciated.

PS Not a programmer just a scripter.

nmiddleton's avatar
11
nmiddleton
asked 2020-05-06 04:10:04 -0500
Wingware Support's avatar
4.1k
Wingware Support
updated 2020-05-06 10:19:59 -0500
edit flag offensive 0 remove flag close merge delete

Comments

It looks like there's a problem with how the environment is set up by your batch file and Wing use of Qt. Could you try starting Wing from the start menu and then set up a new project with an activated environment and the name of a .bat file containing:

@echo off
call "%~dp0\o4w_env.bat"
call "%OSGEO4W_ROOT%\apps\grass\grass78\etc\env.bat"
call qt5_env.bat
call py3_env.bat
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps\grass\grass78\lib;%OSGEO4W_ROOT%\apps\grass\grass78\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins

This is the contents of your .bat file without the final line to start Wing. The .bat file will be run by Wing before it starts ... (more)

Wingware Support's avatar Wingware Support (2020-05-06 14:41:32 -0500) edit

I have taken that approach and added the same paths to the project properties. However Python does seem to be able to locate qgis.core . The pathway is:

C:\Program Files\QGIS 3.12\apps\qgis\python\qgis\core

Any suggestions on what I else I should do? Do I need to add something as PYTHONPATH ?

Thanks, Nick

nmiddleton's avatar nmiddleton (2020-05-06 21:03:24 -0500) edit

Could you give me an example to try here? Is it an import <some-name> that's failing or something else?

Wingware Support's avatar Wingware Support (2020-05-07 09:09:24 -0500) edit

Code:

import processing
from qgis.core import QgsApplication
from processing.core.Processing import Processing
from qgis.analysis import QgsNativeAlgorithms


qgs = QgsApplication([], False)
qgs.initQgis()
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())

Activated Environment: C:\scratch\wing-solution.bat

Effective Python Path: C:\PROGRA~1\QGIS3~1.12\apps\Python37 C:\PROGRA~1\QGIS3~1.12\apps\Python37\Scripts C:\PROGRA~1\QGIS3~1.12\apps\Python37\python37.zip C:\PROGRA~1\QGIS3~1.12\apps\Python37\DLLs C:\PROGRA~1\QGIS3~1.12\apps\Python37\Lib C:\PROGRA~1\QGIS3~1.12\apps\Python37\Lib\site-packages C:\PROGRA~1\QGIS3~1.12\apps\Python37\Lib\site-packages\win32 C:\PROGRA~1\QGIS3~1.12\apps\Python37\Lib\site-packages\win32\lib C:\PROGRA~1\QGIS3~1.12\apps\Python37\Lib\site-packages\pythonwin

.Bat File:

@echo off
call "C:\Program Files\QGIS 3.12\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\apps\grass\grass78\etc\env.bat ...
(more)
nmiddleton's avatar nmiddleton (2020-05-07 22:14:04 -0500) edit

I'm having trouble getting this to work from Wing or from the command line outside of Wing; the first import fails. Are you able to run from the command line?

Wingware Support's avatar Wingware Support (2020-05-08 09:25:44 -0500) edit
add a comment see more comments