0
import sys
sys.path.append("c:\\osgeo4w64\\app\qgis\\pyto\\plugins")
    
import processing, os,glob
layer1 = QgsVectorLayer(layer1ShpFilePath, "layer1", "ogr")
layer2 = QgsVectorLayer(layer2ShpFilePath, "layer2", "ogr")
        
params = {
     'INPUT': layer1,
     'OVERLAY': layer2,
     'OUTPUT': "TEST.shp"
}
        
intersectLayer = processing.run("saga:intersect", params)

I wanted to use pyQgis to find out the intersect polygon between 2 vector layer, but I always encountered error AttributeError: module 'processing' has no attribute 'run' Can anyone please help me? I am writing a python using QGis on a window machine, I have already added the basic QGIS path to the environment variables, but I am no sure if I need to add SAGA package to the window environment variables.

xxestter
  • 441
  • 7
  • 19
  • Have a look at [Using QGIS3 Processing algorithms from standalone PyQGIS scripts (outside of GUI)](https://gis.stackexchange.com/a/279937/4972). You're missing an initialization step, which is a must. – Germán Carrillo Jun 21 '21 at 20:45

1 Answers1

0

had the same problem - it maybe because your import path in sys.path.append is incorrect (I see a typo in your post).

To check your installation you can type sys.path in qgis console:
Python Console
Use iface to access QGIS API interface or Type help(iface) for more info
Security warning: typing commands from an untrusted source can harm your computer
import sys
sys.path
['/usr/share/qgis/python', '/home/<username>/.local/share/QGIS/QGIS3/profiles/default/python', '/home/<username>/.local/share/QGIS/QGIS3/profiles/default/python/plugins', '/usr/share/qgis/python/plugins', '/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/home/<username>/.local/lib/python3.9/site-packages', '/usr/local/lib/python3.9/site-packages', '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages', '/home/<username>/.local/share/QGIS/QGIS3/profiles/default/python']

All the best,