hyriver / pynhd

A part of HyRiver software stack that provides access to NHD+ V2 data through NLDI and WaterData web services
https://docs.hyriver.io
Other
33 stars 8 forks source link

pynhd and shapely import error #64

Closed rmcd-mscb closed 1 year ago

rmcd-mscb commented 1 year ago

What happened?

When creating a conda environment, with dependencies, pynhd and shapely<2.0, importing pynhd results in a shapely import error.

What did you expect to happen?

No response

Minimal Complete Verifiable Example

mamba create -n hyrtest pynhd "shapely<2.0"

In terminal with hyrtest activated:
python
import pynhd

MVCE confirmation

Relevant log output

❯ python
Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pynhd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rmcd/mambaforge/envs/hyrtest/lib/python3.11/site-packages/pynhd/__init__.py", line 9, in <module>
    from pynhd.core import AGRBase, GeoConnex, ScienceBase
  File "/home/rmcd/mambaforge/envs/hyrtest/lib/python3.11/site-packages/pynhd/core.py", line 15, in <module>
    from pygeoogc import ArcGISRESTful, ServiceURL
  File "/home/rmcd/mambaforge/envs/hyrtest/lib/python3.11/site-packages/pygeoogc/__init__.py", line 13, in <module>
    from pygeoogc.pygeoogc import WFS, WMS, ArcGISRESTful, ServiceURL
  File "/home/rmcd/mambaforge/envs/hyrtest/lib/python3.11/site-packages/pygeoogc/pygeoogc.py", line 11, in <module>
    from shapely import LineString, MultiPoint, MultiPolygon, Point, Polygon
ImportError: cannot import name 'LineString' from 'shapely' (/home/rmcd/mambaforge/envs/hyrtest/lib/python3.11/site-packages/shapely/__init__.py)

Anything else we need to know?

No response

Environment

rmcd-mscb commented 1 year ago

FYI - adding python=3.9 to above mamba create command results in the same error.

rmcd-mscb commented 1 year ago

pinning pynhd and pygeoogc back a few versions works

mamba create -n hyrtest_39 python=3.9 pynhd=0.13.6 "shapely<2.0" pygeoogc=0.13.6

cheginit commented 1 year ago

Rich, thanks for reporting the issue.

The new HyRiver libraries (0.14) drop support for shapely<2.0. So, since you're pinning shapely<0.2, it does correctly install the previous version of pynhd (0.13.12) but installs pygeoogc (0.14) since shapely is not a dependency for pygeoogc. So, as a workaround, you need to pin pygeoogc<0.14:

mamba create -n hyrtest pynhd "shapely<2.0" 'pygeoogc<0.14'
cheginit commented 1 year ago

I fixed the issue in pygeoogc. Though, you need to wait for an hour or so, for conda-forge to build the fix and add it to their repository.

rmcd-mscb commented 1 year ago

Thanks @cheginit!