1

I have problem with QGIS. When I run my code in QGIS Python console it works but when I try in console I'm getting an error. Code:

import sys
 
from qgis.core import QgsApplication, QgsProcessingFeedback
from qgis.analysis import QgsNativeAlgorithms
 
QgsApplication.setPrefixPath(r'C:/PROGRA~1/QGIS3~1.16/apps/qgis', True)
qgs = QgsApplication([], True)
qgs.initQgis()
 
# Add the path to processing so we can import it next
sys.path.append(r'C:/PROGRA~1/QGIS3~1.16/apps/qgis/python/plugins')

import processing
from processing.core.Processing import Processing
 
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':'C:/Users/ja/Inne/Desktop/bdot10k_bubd_a/bdot10k_bubd_a.gpkg','JOIN':'C:\\Users\\ja\\Inne\\Desktop\\POLSKA\\PRG_PunktyAdresowe_POLSKA.shp','PREDICATE':[1,5],'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],'METHOD':1,'DISCARD_NONMATCHING':True,'PREFIX':'','OUTPUT':'C:/Users/ja/Inne/Desktop/projekt2.gpkg'})

What is the problem?

Error: >>>
... from qgis.core import QgsApplication, QgsProcessingFeedback
>>> from qgis.analysis import QgsNativeAlgorithms
>>>
... QgsApplication.setPrefixPath(r'C:/PROGRA~1/QGIS3~1.16/apps/qgis', True)
>>> qgs = QgsApplication([], True)
>>> qgs.initQgis()
>>>
... # Add the path to processing so we can import it next
... sys.path.append(r'C:/PROGRA~1/QGIS3~1.16/apps/qgis/python/plugins')
>>>
>>> import processing
>>> from processing.core.Processing import Processing
>>>
... Processing.initialize()
>>> QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
proj_create_from_database: Cannot find proj.db
True
>>> feedback = QgsProcessingFeedback()
>>>
>>> processing.run("native:joinattributesbylocation", {'INPUT':'C:/Users/ja/Inne/Desktop/bdot10k_bubd_a/bdot10k_bubd_a.gpkg','JOIN':'C:\\Users\\ja\\Inne\\Desktop\\POLSKA\\PRG_PunktyAdresowe_POLSKA.shp','PREDICATE':[1,5],'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],'METHOD':1,'DISCARD_NONMATCHING':True,'PREFIX':'','OUTPUT':'C:/Users/ja/Inne/Desktop/projekt2.gpkg'})
proj_create_from_wkt: Cannot find proj.db
proj_create_from_database: Cannot find proj.db
ERROR 1: PROJ: proj_identify: Cannot find proj.db
proj_create_from_wkt: Cannot find proj.db
proj_identify: Cannot find proj.db
proj_get_authorities_from_database: Cannot find proj.db
ERROR 1: PROJ: proj_identify: Cannot find proj.db
  • It looks like a problem with your %PATH% (on Windows) Try setting your GDAL environment variables PROJ_LIB and GEOTIFF_CSV - be sure that you set your paths to the correct bitedness for your python and QGIS - either all 32 bit or all 64 bit. Have a read of stackoverflow.com/questions/14444310/… and add your GDAL folder to the end of your %PATH% or Windows doesn't know to look there for the bits it's trying to find. – Michael Stimson Oct 30 at 7:24
  • did not work for me :/ – datasciencebegginer Oct 30 at 7:40
  • This is a common problem gis.stackexchange.com/search?q=proj.db with GDAL versions >3.0 which are using Proj versions >6. Setting PROJ_LIB correctly is the way to make it work. – user30184 Oct 30 at 8:00
  • What means seeting PROJ_LIB correctly? I have PROJ_LIB - C:\Program Files\QGIS 3.16\share\proj\proj.db – datasciencebegginer Oct 30 at 8:04
  • It means to tell python that path to PROJ_LIB is C:\Program Files\QGIS 3.16\share\proj. I am not Python expert but setting a global environmental variable for your computer could work SET PROJ_LIB="C:\Program Files\QGIS 3.16\share\proj" – user30184 Oct 30 at 9:17
0

Solution:

I have changed interpreter and it works.

Interpreter: C:\Program Files\QGIS 3.16\bin\python-qgis.bat

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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