OSError geos_c could not be found when Installing Shapely [duplicate]
Asked Answered
D

6

29

I'm a newbie to making/plotting on maps with python, been trying to follow this blogpost to generate a world map ( http://sciblogs.co.nz/seeing-data/2011/08/12/plotting-geographic-data-on-a-world-map-with-python/ ). Got stuck with a few things here:

  1. Installing Basemap (a Matplotlib extension for plotting data on geographic projections).

     from mpl_toolkits.basemap import Basemap
     Traceback (most recent call last):
     File "geos_demo.py", line 1, in <module>
     from mpl_toolkits.basemap import Basemap
     ImportError: No module named mpl_toolkits.basemap
    
  2. Install Shapely, but the following error occurs [1]:

  3. Then I went into the geos.py file and change all the references of geos.dll to geos_c.dll, as recommended by the link here: http://osgeo-org.1560.n6.nabble.com/osgeo4w-258-Problems-with-python-shapely-python-2-7-2-td4336816.html

  4. However, the same error [1] occurs.

I'm using Python 2.7.1 and Mac OS 10.7.4. Please let me know if I can provide additional information, and really appreciate any guidance from the community here! Thanks!

[1]

    from shapely.geometry import Point
    Traceback (most recent call last): File "<stdin>", line 1, in <module>
    File "/Users/Desktop/python/ENV/lib/python2.7/site-packages/shapely/geometry/__init__.py", line 4, in <module>
    from geo import box, shape, asShape, mapping
    File "/Users/Desktop/python/ENV/lib/python2.7/site-packages/shapely/geometry/geo.py", line 5, in <module>
    from point import Point, asPoint
    File "/Users/Desktop/python/ENV/lib/python2.7/site-packages/shapely/geometry/point.py", line 7, in <module>
    from shapely.coords import required
    File "/Users/Desktop/python/ENV/lib/python2.7/site-packages/shapely/coords.py", line 8, in <module>
    from shapely.geos import lgeos
    File "/Users/Desktop/python/ENV/lib/python2.7/site-packages/shapely/geos.py", line 59, in <module>
    _lgeos = load_dll('geos_c', fallbacks=alt_paths)
     File "/Users/Desktop/python/ENV/lib/python2.7/site-packages/shapely/geos.py", line 44, in load_dll
    libname, fallbacks or []))
    OSError: Could not find library geos_c or load any of its variants        ['/Library/Frameworks/GEOS.framework/Versions/Current/GEOS', '/opt/local/lib/libgeos_c.dylib']
Danika answered 25/9, 2012 at 7:50 Comment(0)
C
39

For questions 2-4, you have to have GEOS installed on your system. If you have homebrew you can do the following:

brew install geos

Install homebrew here if you don't have it: Link

Chlorinate answered 2/10, 2012 at 0:30 Comment(2)
I still get the same error after doing brew install geos: OSError: Could not find library geos_c or load any of its variants ['/Library/Frameworks/GEOS.framework/Versions/Current/GEOS', '/opt/local/lib/libgeos_c.dylib']Teepee
i have same problem after installing geos using brew install geos.its show Could not find lib geos_c or load any of its variants.Carnassial
T
16

On Ubuntu, to install GEOS, this worked for me:

$ sudo apt-get install libgeos-dev
Terwilliger answered 15/7, 2013 at 17:50 Comment(0)
C
13

With OS X 10.11 (El Capitan) and Boxen, I had do do this:

brew install geos
sudo mkdir /opt/local
sudo ln -s /opt/boxen/homebrew/lib /opt/local/lib

to let Shapely find libgeos_c.dylib in one of the locations it was willing to look for it.

Cleanser answered 13/10, 2015 at 3:16 Comment(2)
I had a problem getting cartopy to run with fink-installed libgeos and had to use this trick to resolve the problem - thanks for the hint!Kindergarten
Jace's recommendation solved the problemUbiquitous
M
2

The problem seems to be that you haven't actually installed the required modules.

Lines of Python code like

from mpl_toolkits.basemap import Basemap

Are import statements that tell your script to use modules (or other bits of Python code) that you need to have already installed.

For each of the packages mentioned (NumPy, Matplotlib, Basemap) you will have to figure out how to install them on your system. In the case of NumPy and Matplotlib this can be complicated because they require compilation. For instance these are theNumpy instructions.

If you just wanted to try playing with the instructions in that blog post then you could use a service like PythonAnywhere which has numpy, matplotlib, and basemap installed already. (disclaimer, I work on PythonAnywhere...)

Megacycle answered 25/9, 2012 at 8:2 Comment(2)
Thanks @aychedee. I have installed numpy and but could not figure out basemap. Does PythonAnywhere help install basemap together with the other libraries?Danika
Hi Michelle, actually basemap is already installed as a standard package. The only difference in getting that tutorial to complete would be that you would have to save the plot as a file and then download it rather than displaying it directly.Megacycle
N
1

on windows 10, python 3.6.5 64bit

  • install osgeo4w
  • add installed folder to PATH e.g. C:\OSGeo4W64\bin (must contain geos_c.dll)
  • restart command line

enjoy

Noncombatant answered 31/5, 2018 at 12:10 Comment(3)
Would you please provide more detail on step 2? Which path? Where? How?Terpineol
install OSGeo4 from page trac.osgeo.org/osgeo4w ... then add folder where you installed OSGeo4 to your PATH e.g. #44272916Noncombatant
Thanks. I had a problem with ModuleNotFoundError: No module named 'shapely._geos' in PyInstaller. After installing OSGeo4W64 I had to simply add --hidden-import shapely._geos to PyInstaller command and it worked.Strigil
E
0

I know it is a pretty old question but, as an alternative to https://mcmap.net/q/189917/-oserror-geos_c-could-not-be-found-when-installing-shapely-duplicate you could use MacPorts to install the geos library:

port install geos

And the installation steps for MacPorts are described here: https://www.macports.org/install.php

Eightieth answered 18/1, 2019 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.