I'm trying write simple code line in PyQgis in PyCharm, have already set environment in PyCharm and seems to be working fine because I can iterate through f.i fields in vector layer proceed with success simpler operations.

from qgis.core import QgsApplication
from qgis.core import QgsVectorLayer
import processing

polygonLayer = QgsVectorLayer(r'E:\Folder\layer.shp','','ogr')
out_fn =r'E:\Folder\out_layer.shp'
dissolve_field = ['_test_field']


After running this few lines i get:

Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3427, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-10-35a681b9a5e0>", line 4, in <module>
  File "C:\OSGeo4W64\apps\qgis\python\plugins\processing\tools\general.py", line 138, in runAndLoadResults
    for param in alg.parameterDefinitions():
AttributeError: 'NoneType' object has no attribute 'parameterDefinitions'

Software set: Pycharm 2020.3.5; QGIS 3.16, installed via OSGEO4W

Could you tell me what i'm doing wrong?


1 Answer 1


It looks like you are trying to use the processing module in a standalone script. You are missing some code to initialize a QgsApplication instance, as well as importing and initializing the processing module. Please try the example below for running QGIS processing algorithms in a standalone script which I have tested with my own file paths. Also, you should use processing.run() instead of runAndLoadResults() since you are not using QGIS gui.

import sys

from qgis.core import QgsApplication 

from qgis.analysis import QgsNativeAlgorithms

# See https://gis.stackexchange.com/a/155852/4972 for details about the prefix 
QgsApplication.setPrefixPath('C:/OSGeo4W64/apps/qgis', True)
qgs = QgsApplication([], False)

# Append the path where processing plugin can be found

import processing
from processing.core.Processing import Processing

input = 'E:\\Folder\\layer.shp'
output = 'E:\\Folder\\out_layer.shp'
dissolve_field = '_test_field'

processing.run("gdal:dissolve", {'INPUT':input,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.