I wrote a code that work well in console python, an example: from qgis.core import QgsProject, QgsLayerTreeGroup, QgsLayerTreeLayer, QgsLayerTree from PyQt5.QtCore import Qt, QVariant, QSettings, QTranslator, qVersion, QCoreApplication from PyQt5 import QtGui from PyQt5.QtGui import QAction, QIcon, QFileDialog, QProgressDialog, QProgressBar, QShortcut, QKeySequence from osgeo import ogr from shutil import copyfile from urllib.request import urlopen import re import processing, glob, os, time...