Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: get_data_dir support for conda Windows enviroments #1029

Closed
Stophface opened this issue Mar 3, 2022 · 9 comments · Fixed by #1030
Closed

BUG: get_data_dir support for conda Windows enviroments #1029

Stophface opened this issue Mar 3, 2022 · 9 comments · Fixed by #1030
Labels
bug installation-issues Issue related to installation problems. windows Windows related issue

Comments

@Stophface
Copy link

Installation method/steps

I freshley installed PyProj according to the docs

conda config --prepend channels conda-forge
conda config --set channel_priority strict
conda create -n pyproj_env pyproj
conda activate pyproj_env

When I try

from pyproj import CRS

I get

PyProj: pyproj unable to set database path. _pyproj_global_context_initialize()

Whats going on there?

Environment Information

  • pyproj version you are attempting to install
  • PROJ version: Rel. 8.2.1, January 1st, 2022
  • Python version: Python 3.9.7
  • Operation System Information: Windows-10-10.0.19042-SP0
@Stophface Stophface added the installation-issues Issue related to installation problems. label Mar 3, 2022
@snowman2
Copy link
Member

snowman2 commented Mar 3, 2022

What is the value of the PROJ_LIB environment variable?

@Stophface
Copy link
Author

Stophface commented Mar 3, 2022

@snowman2 Its: C:\Program Files\PostgreSQL\13\share\contrib\postgis-3.1\proj

I also just got this error:

PROJ: proj_create_from_database: C:\Program Files\PostgreSQL\13\share\contrib\postgis-3.1\proj\proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.

How do handle this situation?

@snowman2
Copy link
Member

snowman2 commented Mar 3, 2022

Sounds like you have conflicting versions of the proj.db. Here are docs for how to look into this: https://pyproj4.github.io/pyproj/stable/gotchas.html#internal-proj-error-sqlite-error-on-select

@Stophface
Copy link
Author

Stophface commented Mar 4, 2022

@snowman2 Thanks for the link. It seems like this is the problem. However, I am not sure how to fix it.

To get data directory being used: pyproj.datadir.get_data_dir()

import pyproj
pyproj.datadir.get_data_dir()

'C:\Program Files\PostgreSQL\13\share\contrib\postgis-3.1\proj'

The order for searching for the data directory can be found in the docstrings of pyproj.datadir.get_data_dir()

pyproj.datadir.get_data_dir()

'C:\Program Files\PostgreSQL\13\share\contrib\postgis-3.1\proj'

How to know in which folder pyproj should look instead for the database? If I know the path to the folder, I set it via
pyproj.datadir.set_data_dir(), right?

@Stophface
Copy link
Author

This is how I found the PATH to PROJ

I looked into this file ...Miniconda3\envs<ENV>\conda-meta\proj--h1cfcee-.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--h1cfcee-. Make sure the folder name is the exact same name you found this file links to: ...Miniconda3\envs<ENV>\conda-meta\proj--h1cfcee-.json. Finally I set my environment variable to the version needed ...Miniconda3\pkgs\proj--h1cfcee-<VERSION\Library\share\proj.

@snowman2 snowman2 reopened this Mar 4, 2022
@snowman2
Copy link
Member

snowman2 commented Mar 4, 2022

prefix_datadir = Path(sys.prefix, "share", "proj")

It might not be a bad idea to better support for the Windows prefix search path. Maybe something like:

conda_windows_prefix_datadir = Path(sys.prefix, "Library", "share", "proj")

@Stophface are you able to share the value of sys.prefix after activating your conda environment?

@snowman2 snowman2 added the windows Windows related issue label Mar 4, 2022
@snowman2
Copy link
Member

snowman2 commented Mar 5, 2022

Looks like adding the windows Library prefix search would be useful here: https://github.com/conda-forge/proj.4-feedstock/blob/9bf81fff5781b937f601a9f1b372f5a819f5bb38/recipe/scripts/activate.sh#L14

@snowman2 snowman2 added this to To do in 3.3.1 Release via automation Mar 5, 2022
@Stophface
Copy link
Author

Stophface commented Mar 5, 2022

@snowman2 Sure, I am not sure how to get it thoug.
Do you mean this?

>>> import sys
>>> sys.prefix
'C:\\Users\\...\\Miniconda3\\envs\\<MY_ENV>'

@snowman2
Copy link
Member

snowman2 commented Mar 6, 2022

Thanks @Stophface, that was helpful. This is something that I think should be added to the logic in pyproj to find the data directory on Windows conda environments.

@snowman2 snowman2 changed the title PyProj: pyproj unable to set database path. _pyproj_global_context_initialize() BUG: get_data_dir support for conda Windows enviroments Mar 6, 2022
@snowman2 snowman2 added the bug label Mar 6, 2022
3.3.1 Release automation moved this from To do to Done Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug installation-issues Issue related to installation problems. windows Windows related issue
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants