0

I am trying to run python startup script for QGIS with the following code:

from qgis.core import *
from qgis.utils import iface
import os
from qgis import processing
project = QgsProject.instance()
project.read('/home/r89/projects/qgis_python/project/main.qgz')
path_to_shapefile = '/home/r89/projects/qgis_python/shapefiles/block1.shp'
block_layer = QgsVectorLayer(path_to_shapefile, "Block layer", "ogr")
project.addMapLayer(block_layer)
iface.setActiveLayer(block_layer)
iface.zoomToActiveLayer()
e = iface.mapCanvas().extent()
x_min = e.xMinimum()
x_max = e.xMaximum()
y_min = e.yMinimum()
y_max = e.yMaximum()
extent = str(x_min) + ',' + str(x_max) + ',' + str(y_min) + ',' + str(y_max) + ' ' + '[EPSG:4326]'
result = processing.run("qgis:tilesxyzmbtiles", {'EXTENT':extent,'ZOOM_MIN':1,'ZOOM_MAX':12, 'OUTPUT_FILE':'/home/r89/projects/qgis_python/output/main.mbtiles'})

os._exit(0)

QGIS throws me an error on start:

An error occurred during execution of following code:
spec.loader.exec_module(module)


Traceback (most recent call last):
  File "", line 1, in 
  File "", line 783, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/home/r89/.local/share/QGIS/QGIS3/startup.py", line 18, in 
    result = processing.run("qgis:tilesxyzmbtiles", {'EXTENT':extent,'ZOOM_MIN':1,'ZOOM_MAX':12, 'OUTPUT_FILE':'/home/r89/projects/qgis_python/output/main.mbtiles'})
AttributeError: module 'qgis.processing' has no attribute 'run'


Python version:
3.8.3 (default, May 17 2020, 18:15:42) 
[GCC 10.1.0]

QGIS version:
3.12.3-București 'București', exported

Python path:
['/usr/share/qgis/python', '/home/r89/.local/share/QGIS/QGIS3/profiles/default/python', '/home/r89/.local/share/QGIS/QGIS3/profiles/default/python/plugins', '/usr/share/qgis/python/plugins', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/r89/.local/lib/python3.8/site-packages', '/usr/lib/python3.8/site-packages', '/home/r89/.local/share/QGIS/QGIS3/profiles/default/python']

When I run this code in QGIS python console, it runs OK. So, I think there could be a problem with processing module running from a startup script rather than from a QGIS app itself. I have seen a question with similar error(module 'qgis.processing' has no attribute 'run') but it doesn`t seem to be helpful to me