On fresh Conda installation of PyProj: pyproj unable to set database path. _pyproj_global_context_initialize()
Asked Answered
S

1

8

I want to use PyProj. I follow the installation instructions given in the documentation

conda config --prepend channels conda-forge
conda config --set channel_priority strict
conda install pyproj

When I run

from pyproj import CRS

I am getting

C:\Users...\Miniconda3\envs\geopandas\lib\site-packages\pyproj_init_.py:89: UserWarning: pyproj unable to set database path. _pyproj_global_context_initialize()

Some information on Python and my system

Python version -> 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:15:42) [MSC v.1916 64 bit (AMD64)]

Operation System Information -> Windows-10-10.0.19042-SP0

Strachan answered 19/10, 2021 at 12:14 Comment(0)
S
18

Quick an dirty

Make sure you are in you environment with conda activate YOUR_ENV:

conda remove --force pyproj

This removes the library from the conda environment. Then do a

pip install pyproj

Now I do not get the error upon calling from pyproj import CRS.

Proper way

However, this is not going through to the core of the problem. I had conflicting versions of the proj.db. Check the value of the PROJ_LIB environment variable. Mine pointed to an installation of postgis. This helps to solve it: https://pyproj4.github.io/pyproj/stable/gotchas.html#internal-proj-error-sqlite-error-on-select

How did I find the path to the installation of proj? I looked into this file ...Miniconda3\envs\<ENV>\conda-meta\proj-<VERSION>-h1cfcee-<VERSION>.json and searched for \pkgs\\proj. Once found, I checked the versins of PROJ installed in this folder C:...\Miniconda3\pkgs\. There are folder named something like proj-<VERSION>-h1cfcee-<VERSION>. Make sure the folder name is the exact same name you found this file links to: ...Miniconda3\envs\<ENV>\conda-meta\proj-<VERSION>-h1cfcee-<VERSION>.json. Finally I set my environment variable to the version needed ...Miniconda3\pkgs\proj-<VERSION>-h1cfcee-<VERSION\Library\share\proj.

Strachan answered 20/10, 2021 at 7:58 Comment(1)
Super helpful! In our case stupid ArcGIS decided to hijack PROJ_LIB...Rentier

© 2022 - 2024 — McMap. All rights reserved.