RuntimeError: PROJ: proj_create_from_database

I am testing simple data reading, but getting error during georeferencing with PROJ variable:
RuntimeError: PROJ: proj_create_from_database

vol = xd.io.open_odim_datatree(fpath)

swp = vol["sweep_0"].ds
swp = swp.assign_coords(sweep_mode=swp.sweep_mode)
swp = swp.wrl.georef.georeference()

I probably have to export some PATH-s for my conda environment, but I am totally out of clue what I have to do specifically. Maybe anyone have more recent experience how to solve it. Thanks!
Wradlib version 2.0.3.

Alright, found something.
Added the following path to the env proj.db file.

import os
os.environ['PROJ_LIB'] = '/home/jorma/anaconda3/envs/steps4/share/proj'

If anyone can add how to put this export to bashrc, I would still be interested in that.

@jorahu Unfortunately I do not have a better advise. I get this type of error every once in a while, but can’t exactly pinpoint the source. I

I’m thinking something is fishy with the PROJ/GDAL conda-env vars. Those might not get set, if the conda environment is not correctly activate. This happens if you just run the python kernel via some IDE or the like. You might check which environment variables are set in the environment after activation.

I have these set in the env after activation:

$ env
GDAL_DATA=/home/kai/data/mambaforge/envs/xr_312/share/gdal
PROJ_NETWORK=ON
PROJ_DATA=/home/kai/data/mambaforge/envs/xr_312/share/proj
>>> pyproj.show_versions()
pyproj info:
    pyproj: 3.6.1
      PROJ: 9.3.1
  data dir: /home/kai/data/mambaforge/envs/xr_312/share/proj
user_data_dir: /user/k.muehlbauer/.local/share/proj
PROJ DATA (recommended version): 1.16
PROJ Database: 1.2
EPSG Database: v10.098 [2023-11-24]
ESRI Database: ArcGIS Pro 3.2 [2023-11-02]
IGNF Database: 3.1.0 [2019-05-24]

System:
    python: 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0]
executable: /home/kai/data/mambaforge/envs/xr_312/bin/python
   machine: Linux-5.14.21-150500.55.19-default-x86_64-with-glibc2.31

Python deps:
   certifi: 2024.2.2
    Cython: 3.0.7
setuptools: 69.0.3
       pip: 23.3.2

HTH,
Kai

1 Like

Thanks Kai! This has been really helpful actually.

The problem is really how I have set up my envs within Jupyterlab. When I activate env and use the “env” command I could also see the GDAL_DATA and PROJ_DATA but not PROJ_LIB that caused the error.
The following would set the PROJ_LIB permanently to the env:
conda env config vars set PROJ_LIB='/home/jorma/anaconda3/envs/steps4/share/proj' -n steps4

But… I have installed all the envs to Jupyterlab with ipykernel, and when I run “env” from some notebook with the same env, a lot of environment variables are missing, including both GDAL_DATA and PROJ_DATA, not to mentions PROJ_LIB.

Only when I manually change the variables through os.environ then the variables are added to the env.

import os
os.environ['PROJ_LIB'] = '/home/jorma/anaconda3/envs/steps4/share/proj'

This turned out to be much more complicated than I would have hoped… Need to look into installing the envs to jupyterlab with ipykernel so that it would grab all the environment variables in the process.

Thanks again, Kai!

@jorahu Thanks for your response which made me dig a bit deeper now.

I’ve tried the following:

  1. create environment for hosting jupyterlab and install nb_conda-kernels (need python=3.10 until upgraded)

    (base) $ mamba create -n jupyterlab python=3.10 jupyter jupyterlab nb_conda_kernels
    
  2. create new working environment with specific packages and install ipykernel/ipywidgets

    (base) $ mamba create -n gdal python=3.12 wradlib gdal pyproj ipykernel ipywidgets
    
  3. activate jupyterlab and run

    (base) $ conda activate jupyterlab
    (jupyterlab) $ jupyter lab
    

Now all available conda environments (which have ipykernel installed) are available from jupyterlab (in jupyterlab environment). And (big point) the environments will be properly activated. Could you please check, if this works for you too?

Thanks,
Kai

Links:

1 Like

I am hosting jupyterlab from base, so all I had to do was install nb_conda_kernels to base. I had ipykernel installed in all other envs. And now totally different options appeared with kernel selection:
image

And now, yes, the environment variables are all included → the env is now “correctly” activated within jupyterlab.

I have always looked away from nb_conda_kernels for some reason… never knew what it did. But apparently it is more than important. In short, the env hosting jupyterlab (can be base) needs nb_conda_kernels installed and all other envs need ipykernel installed.

Thanks a lot, Kai, for looking into it and solving the issue for me! Not wradlib related but rather how my Jupyterlab was set up.

1 Like

Great it works for you too @jorahu. I’ve just stumbled across nb_conda_kernels by accident and it will help a lot here too.

As of now I’ve always installed “EVERYTHING” :man_facepalming: in my environments :joy: Now, I have one dedicated jupyter env. Sigh :innocent:

Best,
Kai

1 Like

Will attach this link here. Need to use the accepted solution, not the one with most upvotes.

As Jupyterlab is fairly popular IDE, maybe someone else also find the additional envs setup useful.

1 Like