qgis/QGIS-Mac-Packager

Cannot find proj.db in QGIS-LTR 3.22; PROJ_LIB env variable not set

Rikuoja opened this issue · 5 comments

Since the corresponding issue(s) in QGIS have been closed, I should report this here:

qgis/QGIS#39801
qgis/QGIS#48574

I have the same problem in all QGIS 3.22 versions on MacOS, including LTR. Trying to run etc. gdalwarp results in

CRITICAL    ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db

I suspect this is because the PROJ_LIB env variable is not set in QGIS python environment. All the other GDAL variables are set correctly:

os.environ
environ({'USER': 'riku', '__CFBundleIdentifier': 'org.qgis.qgis3', 'COMMAND_MODE': 'unix2003', 'LOGNAME': 'riku', 'PATH': '/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/Applications/QGIS-LTR.app/Contents/MacOS/bin:/usr/bin:/bin:/usr/sbin:/sbin', 'PYQGIS_STARTUP': 'pyqgis-startup.py', 'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.ukED6bKMHa/Listeners', 'SHELL': '/bin/zsh', 'HOME': '/Users/riku', 'QT_AUTO_SCREEN_SCALE_FACTOR': '1', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x11', 'TMPDIR': '/var/folders/z6/ld52r6fn1dv_1h70k7z7d9n40000gn/T/', 'XPC_SERVICE_NAME': 'application.org.qgis.qgis3.21928270.21929400', 'XPC_FLAGS': '0x0', 'GDAL_DRIVER_PATH': '/Applications/QGIS-LTR.app/Contents/MacOS/lib/gdalplugins', 'GDAL_DATA': '/Applications/QGIS-LTR.app/Contents/Resources/gdal', 'PYTHONHOME': '/Applications/QGIS-LTR.app/Contents/MacOS', 'GDAL_PAM_PROXY_DIR': '/Users/riku/Library/Application Support/QGIS/QGIS3/profiles/raster_plugin/gdal_pam/', 'LC_CTYPE': 'UTF-8', 'SSL_CERT_DIR': '/Applications/QGIS-LTR.app/Contents/Resources/certs', 'SSL_CERT_FILE': '/Applications/QGIS-LTR.app/Contents/Resources/certs/certs.pem', 'DYLD_LIBRARY_PATH': '/Applications/QGIS-LTR.app/Contents/MacOS/lib'})

There is a merged commit 18f8180 that should have fixed this issue. The commit seems to set env variables, including PROJ_LIB.

However, in 3.22 PROJ_LIB is still not set.

Confirm this is still a problem with the latest LTR 3.22.8 as well.

Hi, Since it is still a problem in 3.22.8, how can I merge rasters in 3.22.8?
I have tried the method in #39801, which is
import os
os.environ["PROJ_LIB"]="/Applications/QGIS.app/Contents/Resources/proj"
But it doesn't work.
How can I merge rasters now?

Just figure out a temporary solution for this: Option - System - Environment and set the PROJ_LIB. Restart!

image

Same issue on QGIS version 3.32.2-Lima running on MacOS 10.13.6.

I looked around the code for PROJ_LIB, and found _patch_proj_lib.py, which adds the variable if missing. If this file is still in use, then I might have found a possible cause of the bug.

Possible regression

The only place where _patch_proj_lib is mentioned in the repository is in python_pyproj/recipe.sh:

try cp -av $RECIPES_PATH/python_pyproj/_patch_proj_lib.py $PYPROJ_EGG/pyproj/_patch_proj_lib.py
try ${SED} "s;from pyproj import _datadir;from pyproj import _patch_proj_lib, _datadir;g" $PYPROJ_EGG/pyproj/__init__.py

The sed command in line 40 adds _patch_proj_lib to a line matching from pyproj import _datadir inside pyproj/__init__.py. Locally, this file is in
/Applications/QGIS.app/Contents/Resources/python/site-packages/pyproj-3.2.0-py3.9-macosx-10.13.0-x86_64.egg/pyproj/__init__.py.
However, the line from pyproj import _datadir is nowhere to be found as it seems it was removed from pyproj a while back. Therefore, sed does nothing and the patch is not imported.

Could it be that_patch_proj_lib.py was added to QGIS-Mac-Packager before the updated pyproj was added to QGIS?

Having the same issue when try to run GDAL "Asignar proyeccion" in QGIS 3.34.9 on MacOS Sonoma 14.6.

The solution of overwrite PROJ_LIB with the path /Applications/QGIS-LTR.app/Contents/Resources/proj works fine for me
image