qgis / QGIS-Mac-Packager

Scripts for Official QGIS MacOS Packages
https://www.qgis.org
GNU General Public License v2.0
54 stars 21 forks source link

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

Open Rikuoja opened 2 years ago

Rikuoja commented 2 years ago

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

https://github.com/qgis/QGIS/issues/39801 https://github.com/qgis/QGIS/issues/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 https://github.com/qgis/QGIS-Mac-Packager/commit/18f8180db42b343cc425ba0aabef7b4a29af997b 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.

spatialthoughts commented 2 years ago

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

yukihuang0422 commented 1 year ago

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?

rickyking commented 1 year ago

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

image
kidhanis commented 9 months ago

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: https://github.com/qgis/QGIS-Mac-Packager/blob/1597c0499a968141670ace3f347262bc6d604fb7/qgis_bundle/recipes/python_pyproj/recipe.sh#L38-L40 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?