[Bug report] Cannot import after release 0.18.2 if shapely is not installed
bug
### Describe the bug
Cannot import after latest release
Package uses `shapely.Geometry` as return type but shapely is an optional package and only imported in try..except.
Issue introduced here: https://github.com/geoalchemy/geoalchemy2/commit/b6440a2fe70dd0629d3b882c8fb0e7bfba13f922#diff-deacd1a957b6264b25a2f4a5b2b1d9ccb3be0cb056e7e3d767363a17e66dbc06R38-R39
### Optional link from https://geoalchemy-2.readthedocs.io which documents the behavior that is expected
_No response_
### To Reproduce
```Python
uv pip install geoalchemy2
import geoalchemy2
```
### Error
```Python traceback
(geol2) ➜ geol2 python
Python 3.12.7 (main, Oct 16 2024, 07:12:08) [Clang 18.1.8 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import geoalchemy2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/__init__.py", line 3, in <module>
from geoalchemy2 import admin
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/admin/__init__.py", line 9, in <module>
from geoalchemy2.admin import dialects
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/admin/dialects/__init__.py", line 3, in <module>
from geoalchemy2.admin.dialects import common # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/admin/dialects/common.py", line 11, in <module>
from geoalchemy2.types import Geometry
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/types/__init__.py", line 33, in <module>
from geoalchemy2.types import dialects
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/types/dialects/__init__.py", line 4, in <module>
from geoalchemy2.types.dialects import geopackage # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/types/dialects/geopackage.py", line 3, in <module>
from geoalchemy2.types.dialects.sqlite import bind_processor_process # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/types/dialects/sqlite.py", line 9, in <module>
from geoalchemy2.shape import to_shape
File "/private/tmp/geol2/.venv/lib/python3.12/site-packages/geoalchemy2/shape.py", line 38, in <module>
def to_shape(element: WKBElement | WKTElement) -> shapely.Geometry:
^^^^^^^
NameError: name 'shapely' is not defined
```
### Additional context
_No response_
### GeoAlchemy 2 Version in Use
0.18.2
### Python Version
3.12
### Operating system
MacOS
关闭于 2026-02-20 2 条评论