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.
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:
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)
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
Could you give me an example to try here? Is it an import <some-name> that's failing or something else?
Code:
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:
(more)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?