So, I have this little script (which I would like to build more upon).
I was able to make it work in QGIS3.2 (just change all paths and environments to 3.2) but now, after deleting QGIS 3.2 and installing 3.4 or 3.6 it does not work anymore.
I am able to start QgsApplication. But after testing, isValidLayer(), the result is false. So any processing creates empty output.
Environments and python is set up only for QGIS3.6 (Python37). If I install QGIS 3.2 and set it up back, all works just fine. But i am not able to change it to version 3.6. It is driving me crazy!
Any ideas?
import os, sys, datetime, glob, re, pprint
from qgis.core import *
from qgis.analysis import QgsNativeAlgorithms
sys.path.append(r'c:/SW/QGIS3.6/apps/qgis/python/plugins')
#-------------------------------------------------------------
# start QGIS processing application
QgsApplication.setPrefixPath(r'C:/SW/QGIS3.6/apps/qgis', True)
print(QgsApplication.prefixPath())
qgs = QgsApplication([], False)
qgs.initQgis()
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
#-------------------------------------------------------------
# folder = r'd:\01_Projects'
# files = glob.glob(folder + '/**/BUDOVY_P.shp', recursive=True)
out = r''
file = r'd:\01_Projects\BUDOVY_P.shp'
layer = QgsVectorLayer(file, 'tmp', 'ogr')
print(layer.isValid())
qgs.exitQgis()
Results is:
C:/SW/QGIS3.6/apps/qgis
False
pth file in site-packages for setting up PyCharm:
C:\SW\QGIS3.6\apps\qgis\python
C:\SW\QGIS3.6\apps\Python37\
C:\SW\QGIS3.6\apps\Python37\Lib\
C:\SW\QGIS3.6\apps\Python37\Lib\site-packages
C:\SW\QGIS3.6\bin
C:\SW\QGIS3.6\include
C:\SW\QGIS3.6\apps\qgis\bin
C:\SW\QGIS3.6\apps\qgis\python\plugins
C:\SW\QGIS3.6\apps\grass\grass-7.6.0
C:\SW\QGIS3.6\apps\Qt5\bin
env variables:
C:\SW\QGIS3.6\apps\qgis\bin
C:\SW\QGIS3.6\bin
C:\SW\QGIS3.6\apps\Python37\Scripts
The same part run in QGIS returns:
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 lead to data loss and/or leak
file = r'd:/01_Projects/BUDOVY_P.shp'
layer = QgsVectorLayer(file, 'tmp_lyr', 'ogr')
print(layer.isValid())
True