Closed danschef closed 1 year ago
@danschef, I'm sure this must be frustrating.
This issue relates to proj
(https://github.com/conda-forge/proj.4-feedstock) rather than pyproj
, since the variable is for the proj
package's data.
In proj
>=9.1.0, the environment variable is now $PROJ_DATA
instead of $PROJ_LIB
. It was changed in proj
here:
https://github.com/OSGeo/PROJ/pull/3253
and in proj.4-feedstock
here:
https://github.com/conda-forge/proj.4-feedstock/pull/125
I think if you're using $PROJ_LIB
in your own code, you will now need to first check for $PROJ_DATA
and then fall back on $PROJ_LIB
.
Thanks, then this should probably respected in gdal, right? In the meanwhile, I can simply set PROJ_LIB with PROJ_DATA in my code.
@danschef, you're right that recent versions of gdal should presumably know about this change.
Could you provide a more detailed reproducer for the gdal error you're seeing and maybe post an issue on the gdal feedstock pointing it to this discussion?
We have been noticing a similar error in the geopandas docs (built on readthedocs), that we couldn't reproduce locally, and that might be related (https://github.com/geopandas/geopandas/issues/2683, https://github.com/geopandas/geopandas/issues/2652#issuecomment-1326668393, cc @ocefpaf)
I am wondering if it could somehow be related to the fact that released Fiona is not yet updated to work with PROJ_DATA instead of PROJ_LIB. Although when using conda, I would assume that the proj bindings in Fiona (through gdal?) will still find the data at the expected built-in path, even when PROJ_LIB is not set.
I could actually reproduce it by mimicking the output of readthedocs, by not activating the environment but using the full path to the python executable:
Create environment with released fiona (1.8.22) and latest gdal/proj
mamba create -n test-proj-data python=3.10 fiona
Run python by using full path (without activating environment):
$ /home/joris/miniconda3/envs/test-proj-data/bin/python
Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:26:04) [GCC 10.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiona
ERROR 1: PROJ: proj_create_from_database: Open of /home/joris/miniconda3/envs/test-proj-data/share/proj failed
>>> import fiona.env
>>> fiona.env.PROJDataFinder().search()
'/home/joris/miniconda3/envs/test-proj-data/share/proj'
What is strange is that this directory is actually the correct directory that contains proj.db, so it is not clear to me why PROJ is raising this error.
Sorry for posting here in case it is not actually related. In any case, it is not related to pyproj in my case (but maybe @danschef for your actual use case where you encountered this, you also had other packages installed like fiona?)
@jorisvandenbossche, if you don't activate the environment, neither the $PROJ_LIB
variable in the past nor the $PROJ_DATA` variable now will be set, so I don't see how this would have change recently.
I properly activated the environment, which sets $PROJ_DATA
. But yes, I also had other libraries like fiona and gdal installed and importing fiona raises the error as in https://github.com/conda-forge/pyproj-feedstock/issues/130#issuecomment-1370918801.
To me, this looks like fiona needs to be updated to use $PROJ_DATA
.
@danschef, that does seem like at least one likely source of the problem.
@xylar yes, I know that not activating the environment doesn't set the env variable (and myself I always work with activated envs), but it's just that it is for now the only way that I could reproduce this error locally.
In a properly activated environment created with mamba create -n test-proj-data python=3.10 fiona
, running import fiona
does not print any error for me.
(and to be clear, I also doesn't actually "error", code actually runs fine, but PROJ for some reason prints an error about not being able to open the path)
@danschef do you also get the error with the mamba create example I gave? Or can you provide a full reproducer with output of the different steps?
Fiona PR Toblerity/Fiona#1128
Yes, but so that is only in 1.9.x, thus not yet released (maybe something to bring up with Fiona)
Here is the 1.9 release issue: https://github.com/Toblerity/Fiona/issues/1053
Ok, it seems like the issue is somehow related to PyCharm. I just created an environment with mamba create -n fiona 'python=3.10' fiona
(installs fiona 1.8.22 py310ha325b7b_5 + dependencies), activated it and on the conda command line I can import fiona without any issues. Also $PROJ_DATA
is set correctly.
However, if I set this environment as the interpreter in PyCharm (2022.3.1), and import fiona on a Python console within PyCharm, I get ERROR 1: PROJ: proj_create_from_database: Open of /home/me/mambaforge/envs/fiona/share/proj failed
and neither $PROJ_DATA
nor $PROJ_LIB
are set. This is strange because, e.g., $GDAL_DATA
is properly set, so PyCharm seems to activate the environment as it should.
I can of course set $PROJ_DATA
manually in PyCharm actually this should work out of the box.
@danschef, I realize this might not be resolved yet but it isn't ultimately a pyproj
issue so I'm closing it. If the issue persists, I'd follow up on the fiona
, proj.4
and any other affecte feedstocks.
Solution to issue cannot be found in the documentation.
Issue
The pyproj>=3.4.0 builds (e.g., py310hb1338dc_2) do not set the
PROJ_LIB
environment variable. This breaks my code when running any kind of reprojection (e.g., from gdalwarp) and raises the following error:ERROR 1: PROJ: proj_create_from_database: Open of /path/to/myenv/share/proj failed
pyproj<3.4.0:
pyproj>=3.4.0:
Installed packages
Environment info