PROJ_LIB environment variable is not correctly set for powershell

Hello,
When PROJ is installed from anaconda official repositories, an environment variable “PROJ_LIB” is not correctly set for powershell.
The error “PROJ: proj_create_from_database: Cannot find proj.db” occurs.
This seems to be because activation and deactivation scripts do not exist in CONDA_PREFIX/etc/conda/activate.d and CONDA_PREFIX/etc/conda/deactivate.d.

The versions are,

  • conda: 23.5.0
  • proj: 6.2.1
  • pypro: j2.6.1.post1

Adding following scripts into activate.d and deactivate.d fixes this situation.

# CONDA_PREFIX/etc/conda/activate.d/proj4-activate.ps1
if ($env:PROJ_LIB) {
    $env:_CONDA_SET_PROJ_LIB=$env:PROJ_LIB
}

$ENV:PROJ_LIB="$ENV:CONDA_PREFIX\Library\share\proj"
# CONDA_PREFIX/etc/conda/deactivate.d/proj4-deactivate.ps1
if ($env:PROJ_LIB) {
    $env:_CONDA_SET_PROJ_LIB=$env:PROJ_LIB
}

$ENV:PROJ_LIB="$ENV:CONDA_PREFIX\Library\share\proj"

I’m sorry. The above proj4-deactivate.ps1 is not correct.

proj4-deactivate.ps1 is

# CONDA_PREFIX/etc/conda/deactivate.d/proj4-deactivate.ps1
remove-item ENV:PROJ_LIB -ErrorAction Ignore
if ($ENV:_CONDA_SET_PROJ_LIB){
  $ENV:PROJ_LIB=$ENV:_CONDA_SET_PROJ_LIB
  Remove-Item ENV:_CONDA_SET_PROJ_LIB
}