Cannot import shapely.geometry in Python

2019-09-13 05:36发布

问题:

I am trying to import Multipoint from shapely.geometry in IPython notebook.

When I do "from shapely.geometry import MultiPoint", I get the error "No module named shapely.geometry".

So, I tried doing "!pip install --upgrade shapely", for this I get the error

Running setup.py (path:/tmp/pip-build-NyZFjW/shapely/setup.py) egg_info for package shapely
Failed `CDLL(libgeos_c.so.1)`
Failed `CDLL(libgeos_c.so)`
Traceback (most recent call last):
  File "<string>", line 17, in <module>
  File "/tmp/pip-build-NyZFjW/shapely/setup.py", line 38, in <module>
    from shapely._buildcfg import geos_version_string, geos_version, \
  File "shapely/_buildcfg.py", line 167, in <module>
    fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
  File "shapely/_buildcfg.py", line 161, in load_dll
    libname, fallbacks or []))
OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
Complete output from command python setup.py egg_info:
Failed `CDLL(libgeos_c.so.1)`

I need to find my cluster centroids of each cluster that's formed using DBSCAN Algorithm. That can be done only if this issue is resolved.

Any help would be greatly appreciated.

回答1:

I had this OSError that I found in your output:

Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']

To solve that I installed the lib-geos, by running:

$ sudo apt-get install libgeos-dev