I am trying to execute the following code on my Windows 10 with QGIS 2.18.20.
from qgis.core import *
from qgis.utils import *
import os, sys
QgsApplication.setPrefixPath("C:/Program Files/QGIS 2.18/apps/qgis-ltr", True)
app = QApplication([], True)
QgsApplication.initQgis()
sys.path.append('C:/Program Files/QGIS 2.18/apps/qgis-ltr')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
path_to_layers = "path"
gebaude = path_to_layers + "layer1.shp"
duek = path_to_layers + "layer2.shp"
ergebnisse = path_to_layers + "result.shp"
general.runalg("qgis:joinattributesbylocation", gebaude, duek, ['intersects','overlaps','within'], 0, 0, 'sum', 1, ergebnisse)
print("Finished with no issues")
However, I am encountering the error
Traceback (most recent call last):
File "path_to_the_python_code\Gebaeude.py", line 1, in <module>
from qgis.core import *
ImportError: No module named qgis.core
Have already seen similar threads on this topic but can not really understand how and where I should adjust the full path to the Python executable under the QGIS installation.
set PYTHONPATH="C:/Program Files/QGIS 2.18/apps/Python27"
set PATH="C:/Program Files/QGIS 2.18/bin"
I tried the above set-ups in OSGeo4W Shell through the bat file but no success yet. What I am doing wrong?
References: