I am trying to work with an active QGIS from a jupyter notebook - specifically I'd like to be able to access iface so I can perform some layer calculations.
I am having trouble getting the map layers and working with the iface.
from qgis.core import *
import qgis.utils
from qgis.utils import iface, plugins
import numpy
import pandas
import pathlib, os, sys
project_name= r"C:\path-to-project.qgz"
app= QgsApplication([], False)
QgsApplication.setPrefixPath(r"C:\OSGeo4W\apps\qgis", True)
QgsApplication.initQgis()
current_project= QgsProject.instance()
current_project.setFileName(project_name)
print(current_project) #this prints a project instance
print(current_project.mapLayers()) #this returns an empty dictionary {}
layer = iface.activeLayer() #this gives an error: NoneType has no method activeLayer
layers = iface.mapCanvas().layers() #same error as above: it thinks iface is None
For some reason it is not able to use iface and gives me a NoneType error.
How do I work with the currently running QGIS instance from a jupyter notebook and have access to the map layers?