简体   繁体   English

安装Shapely时找不到OSError geos_c

[英]OSError geos_c could not be found when Installing Shapely

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/). 我是使用python在地图上制作/绘图的新手,一直试图按照这个博文来生成世界地图(http://sciblogs.co.nz/seeing-data/2011/08/12/plotting-geographic-数据上-A-世界地图与 - 蟒/)。 Got stuck with a few things here: 在这里遇到了一些问题:

  1. Installing Basemap (a Matplotlib extension for plotting data on geographic projections). 安装底图(用于绘制地理投影数据的Matplotlib扩展)。

     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]: 安装Shapely,但发生以下错误[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 然后我进入了geos.py文件并将geos.dll的所有引用更改为geos_c.dll,如下所示: http ://osgeo-org.1560.n6.nabble.com/osgeo4w-258- 问题与-蟒蛇,身材匀称的Python-2-7-2-td4336816.html

  4. However, the same error [1] occurs. 但是,会出现相同的错误[1]。

I'm using Python 2.7.1 and Mac OS 10.7.4. 我正在使用Python 2.7.1和M​​ac 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] [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']

For questions 2-4, you have to have GEOS installed on your system. 对于问题2-4,您必须在系统上安装GEOS。 If you have homebrew you can do the following: 如果您有自制软件,您可以执行以下操作:

brew install geos

Install homebrew here if you don't have it: http://mxcl.github.com/homebrew/ 如果你没有自制软件,请在这里安装自制软件: http//mxcl.github.com/homebrew/

在Ubuntu上,要安装GEOS ,这对我GEOS

$ sudo apt-get install libgeos-dev

With OS X 10.11 (El Capitan) and Boxen, I had do do this: 使用OS X 10.11(El Capitan)和Boxen,我已经这样做了:

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. 让Shapely在其愿意寻找的一个位置找到libgeos_c.dylib

The problem seems to be that you haven't actually installed the required modules. 问题似乎是您实际上没有安装所需的模块。

Lines of Python code like 像Python的代码行

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. import语句是否告诉您的脚本使用您已经安装的模块(或其他Python代码)。

For each of the packages mentioned (NumPy, Matplotlib, Basemap) you will have to figure out how to install them on your system. 对于提到的每个包(NumPy,Matplotlib,Basemap),您必须弄清楚如何在系统上安装它们。 In the case of NumPy and Matplotlib this can be complicated because they require compilation. 在NumPy和Matplotlib的情况下,这可能很复杂,因为它们需要编译。 For instance these are theNumpy instructions . 例如, 这些是Numpy指令

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 . 如果您只是想尝试播放该博客文章中的说明,那么您可以使用像PythonAnywhere这样的服务,它已经安装了numpy,matplotlib和basemap (disclaimer, I work on PythonAnywhere...) (免责声明,我在PythonAnywhere上工作......)

on windows 10, python 3.6.5 64bit 在Windows 10上,python 3.6.5 64bit

  • install osgeo4w 安装osgeo4w
  • add installed folder to PATH eg C:\\OSGeo4W64\\bin (must contain geos_c.dll) 将已安装的文件夹添加到PATH,例如C:\\ OSGeo4W64 \\ bin(必须包含geos_c.dll)
  • restart command line 重启命令行

enjoy 请享用

I know it is a pretty old question but, as an alternative to https://stackoverflow.com/a/12683010/597743 you could use MacPorts to install the geos library: 我知道这是一个非常古老的问题,但作为https://stackoverflow.com/a/12683010/597743的替代方案,您可以使用MacPorts来安装地理库:

port install geos

And the installation steps for MacPorts are described here: https://www.macports.org/install.php 此处介绍了MacPorts的安装步骤: https//www.macports.org/install.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM