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

Shapely and Fiona import order issues #1107

Open
pronebird opened this issue Mar 19, 2021 · 3 comments
Open

Shapely and Fiona import order issues #1107

pronebird opened this issue Mar 19, 2021 · 3 comments

Comments

@pronebird
Copy link

pronebird commented Mar 19, 2021

Please note

If you are reporting an installation or module import issue, please note that
this project only accepts reports about problems with packages downloaded from
the Python Package Index. Conda users should take issues to one of the
following trackers:

Expected behavior and actual behavior.

So since #553 the trick was to import Shapely first. This stopped working.

The following code:

# import order is important, see https://github.com/Toblerity/Shapely/issues/553
from shapely.geometry import shape, mapping
import fiona

Emits this:

Traceback (most recent call last):
  File "~/scripts/extract-geo-data.py", line 18, in <module>
    import fiona
  File "/usr/local/lib/python3.9/site-packages/fiona/__init__.py", line 84, in <module>
    from fiona.collection import BytesCollection, Collection
  File "/usr/local/lib/python3.9/site-packages/fiona/collection.py", line 9, in <module>
    from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
ImportError: dlopen(/usr/local/lib/python3.9/site-packages/fiona/ogrext.cpython-39-darwin.so, 2): Symbol not found: _GEOSArea
  Referenced from: /usr/local/opt/libspatialite/lib/libspatialite.7.dylib
  Expected in: flat namespace
 in /usr/local/opt/libspatialite/lib/libspatialite.7.dylib

Flipping fiona and shapely imports does the trick, however if feels that something wrong is happening behind the scenes.

Steps to reproduce the problem.

(For example, a script with required data)

Operating system

macOS Big Sur 11.1

Shapely version and provenance

I am running Shapely 1.7.1 and Fiona 1.8.18 installed with pip3, GDAL 3.2.1 from Homebrew (if that matters)

pronebird added a commit to mullvad/mullvadvpn-app that referenced this issue Mar 19, 2021
pronebird added a commit to mullvad/mullvadvpn-app that referenced this issue Mar 19, 2021
pronebird added a commit to mullvad/mullvadvpn-app that referenced this issue Mar 22, 2021
@Jeremiah-England
Copy link
Contributor

Jeremiah-England commented Mar 26, 2021

Not sure if it's related but import order of fiona and shapely can matter in Windows as well (see here).

There is also #887 where it is reported that flipping the imports of osgeo and shapely solves an issue.

Edit: Ah, I see you already linked a relevant historical issue. Should have ready more carefully first!

@sgillies
Copy link
Contributor

sgillies commented Mar 30, 2021

@pronebird it looks to me like you might have installed fiona like pip install --no-binary fiona fiona. The clue is seeing /usr/local/opt/libspatialite/lib/libspatialite.7.dylib and not a path within your Python installation. Is that the case? If so, I recommend uninstalling shapely and doing the same for that.

@pronebird
Copy link
Author

pronebird commented Mar 31, 2021

@sgillies I have installed it from requirements.txt hashed with hashin tool:

pip3 install -r requirements.txt

I think that this particular libspatialite can be coming from gdal installed via Homebrew. I need it for other things. I'll have a look at what's being installed in site-packages later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants