I'm following the following instructions on getting Python to work with QGIS, outside the QGIS GUI itself: Using PyQGIS in custom applications.
But for some reason the GUI is not appearing, yet the layer seems to be loading fine and it also returns the correct feature count. What am I doing wrong?
from qgis.core import *
qgs = QgsApplication([], True)
qgs.initQgis()
vlayer = QgsVectorLayer("test.gpkg")
if not vlayer.isValid():
raise Exception("Layer failed to load!")
project = QgsProject.instance()
project.addMapLayer(vlayer)
print(vlayer.featureCount());
# Write your code here to load some layers, use processing
# algorithms, etc.
qgs.exitQgis()
Best Answer
Any GUI doesn't appear when using PyQGIS standalone application. You have to construct it.
Here is an example: