from qgis.core import QgsApplication # Initialize a new QGIS application instance qgs = QgsApplication([], True) # Set the prefix path where QGIS is installed qgs.setPrefixPath('/usr', True) # Initialize the application qgs.initQgis() # Use the QGIS API to perform tasks # ... # Exit the application qgs.exitQgis()
from qgis.core import QgsApplication # Initialize a new QGIS application instance qgs = QgsApplication([], True) # Set the prefix path where QGIS is installed qgs.setPrefixPath('C:/OSGeo4W64/apps/qgis-ltr', True) # Initialize the application qgs.initQgis() # Use the QGIS API to perform tasks # ... # Exit the application qgs.exitQgis()In this example, a new QgsApplication instance is created and initialized, the prefix path is set to the location where QGIS is installed on Windows, and then the application is exited. This example uses the Windows path convention for the QGIS installation, so the package library is likely to be the Windows version of QGIS.