Showing posts with label QGIS. Show all posts
Showing posts with label QGIS. Show all posts

Thursday, February 27, 2025

Using QGIS - Update

 QGIS is a widely used, free and open source, GIS software package.  This is an update on how to use it with PyScripter.   I have used the currently latest version for Windows (3.42) but you can adapt the instructions to other recent versions of QGIS.

Create a command file "PyScripter-QGIS.cmd" with the following content:

@echo off
rem Adapt the following line to match your installation
set QGIS_ROOT=C:\Program Files\QGIS 3.42.0
call "%QGIS_ROOT%\bin\o4w_env.bat"
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
@echo on
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set GDAL_FILENAME_IS_UTF8=YES
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
set PYTHONPATH=%QGIS_ROOT%\apps\qgis\python;%PYTHONPATH%
pushd "c:\Program Files\PyScripter"
rem Adapt the following line to match the python version that comes with QGIS
start "PyScripter" /B "PyScripter.exe" --PYTHON312 --PYTHONDLLPATH="%QGIS_ROOT%\apps\Python312"
popd

Save it anywhere you want and run it. 

Then in the PyScripter python interpreter you can do:

*** Python 3.12.9 (main, Feb  7 2025, 14:34:44) [MSC v.1938 64 bit (AMD64)] on win32. ***
*** Remote Python engine is active ***
>>> from qgis.core import *
>>> import qgis.utils
>>> from PyQt5.QtCore import QSettings
>>> 

That's it.

Monday, June 5, 2023

Using PyScripter with QGIS

This is a solution contributed by Andreas (github user name amr).  For a complete integration of PyScripter with QGIS you need two things:

  1. Batch-File: The following is for the LTR-version of QGIS. It is a modified version of the existing python-qgis-ltr.bat in the folder "OSGeo4W\bin". Some changes were made to it, essentially using absolute paths to both the OSGeo4W and PyScripter installation folders. Please change the paths, if yours differ!
  2.  

    @echo off
    :: path for OSGeo4W/QGIS
    set O4W=C:\OSGeo4W
    :: path for PyScripter
    set PYSC=C:\Program Files\PyScripter
    
    :: changed start procedure
    call "%O4W%\bin\o4w_env.bat"
    @echo off
    :: add python dir to path
    path %OSGEO4W_ROOT%\apps\qgis-ltr\bin;%OSGEO4W_ROOT%\apps\Python39;%PATH%
    set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis-ltr
    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-ltr\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
    set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis-ltr\python;%PYTHONPATH%
    
    :: start PyScripter
    start "PyScripter" /B "%PYSC%\PyScripter.exe" --PYTHON39 --pythondllpath=%OSGEO4W_ROOT%\apps\python39 %*
    
    
  3. Start-Script for the Python-Interpreter: It uses the path variable and adds each path to the DLL-search path. Store this as "sitecustomize.py" into the folder OSGeo4W\apps\Python39
#sitecustomize.py
import os
for p in os.getenv("PATH").split(";"):
    if os.path.exists(p):
        os.add_dll_directory(p)

Thursday, October 25, 2018

Using PyScripter with QGIS

QGIS is a free and open source GIS System.  However it comes with an unusual setup.  To use it with Pyscripter you need to:

  • copy  python3.exe and python36.dll (or python37.dll for recent versions) from the bin folder (osgeo4w\bin) to the python folder (osgeo4w\apps\Python36 or osgeo4w\apps\Python36)
  • rename python3.exe to python.exe
Then the installation is similar to the ones described here