I have tried to setup my PyQGIS development environment to use PyCharm, by opening my script in Pycharm, then change the python interpreter to the path C:/ProgramFiles/QGIS 3.28.3/bin/python-qgis.bat (so according to this Using PyQGIS in PyCharm). However, while it now recognizes the qgis library and seems to work properly, it doesn't update the view or the TOC in the open instance of QGIS.
For example this code does print the source layer, but no layer is added to the TOC of the open QGIS instance, as it would when scripting in the python code editor opened in QGIS:
from qgis.core import *
import os
import sys
Get the data
source = QgsVectorLayer(path='path/to/file.shp',
baseName = 'source',
providerLib='ogr')
if not source.isValid():
print("Layer failed to load!")
else:
QgsProject.instance().addMapLayer(source)
print(source)
Do I need to refresh QGIS? And if so, how can I do this from the script, so that it updates the view automatically?
QGIS 3.28
Windows 10
