1

系统:Mac OSX

我是 Python 的新用户,目前正在探索 GIS。尝试使用 geopandas 读取形状文件,但我得到:OSError:找不到 libspatialindex_c 库文件

正常使用 Python 3.7,但由于 geopandas 在这方面存在依赖性问题,因此按照此处的建议在 Python2 上运行。

我在这里所做的是使用mac终端,使用python2创建新环境并在那里安装geopandas并尝试读取形状文件。

conda create -n mytest python=2.7 geopandas -c conda-forge

源激活 mytest

导入地理熊猫

geopandas.read_file('Random_points_twitter.shp')

  id   xcoord    ycoord  data_twitt  

0 0 5.27735 50.25398 0

1 1 3.29896 51.32356 1

2 2 3.29896 51.32356 2

我可以在终端中成功阅读此内容。但是在浏览器中,它返回一个错误。

我所做的是首先在我的新环境上安装 jupyter 并在浏览器上运行笔记本(代码如下)

(mytest) conda install jupyter

(mytest) jupyter-notebook

在带有新笔记本的浏览器上,尝试导入和读取形状文件(类似于我在终端中所做的),但它给了我这个错误:

#

() ----> 1 导入 geopandas 中的 OSError Traceback (最近一次调用最后一次)

/Users/rldy/anaconda/lib/python2.7/site-packages/geopandas/ init .py in () ----> 1 from geopandas.geoseries 从 geopandas.geodataframe 导入 GeoSeries 2 从 geopandas.io 导入 GeoDataFrame 3 4 .file 从 geopandas.io.sql 导入 read_file 5 导入 read_postgis

/Users/rldy/anaconda/lib/python2.7/site-packages/geopandas/geoseries.py in () 10 11 from geopandas.plotting import plot_series ---> 12 from geopandas.base import GeoPandasBase, _series_unary_op, _CoordinateIndexer 13 14

/Users/rldy/anaconda/lib/python2.7/site-packages/geopandas/base.py in () 12 13 try: ---> 14 from rtree.core import RTreeError 15 HAS_SINDEX = True 16 except ImportError:

/Users/rldy/anaconda/lib/python2.7/site-packages/rtree/ init .py in () ----> 1 from .index import Rtree 2 3 from .core import rt 4 5 version = '0.8. 3'

/Users/rldy/anaconda/lib/python2.7/site-packages/rtree/index.py in () 3 import pprint 4 ----> 5 from . 导入核心 6 导入 ctypes 7 尝试:

/Users/rldy/anaconda/lib/python2.7/site-packages/rtree/core.py in () 123 124 如果 lib_name 为 None:--> 125 raise OSError("Could not find libspatialindex_c library file") 126 127 rt = ctypes.CDLL(lib_name)

OSError: 找不到 libspatialindex_c 库文件

#

我的 conda 列表(如下)已经安装了 libspatial,但是当使用浏览器在 Jupyter Notebook 上运行时给我这个错误。有任何想法吗?

backports:                     1.0-py27_1            conda-forge
backports.functools_lru_cache: 1.4-py27_1            conda-forge
backports_abc:                 0.5-py27_0            conda-forge
ca-certificates:               2017.11.5-0           conda-forge
certifi:                       2017.11.5-py27_0      conda-forge
clangdev:                      5.0.0-default_0       conda-forge
click:                         6.7-py_1              conda-forge
click-plugins:                 1.0.3-py27_0          conda-forge
cligj:                         0.4.0-py27_0          conda-forge
curl:                          7.55.1-0              conda-forge
cycler:                        0.10.0-py27_0         conda-forge
descartes:                     1.1.0-py27_0          conda-forge
enum34:                        1.1.6-py27_1          conda-forge
expat:                         2.2.5-0               conda-forge
fiona:                         1.7.9-py27_0          conda-forge
freetype:                      2.8.1-0               conda-forge
freexl:                        1.0.4-0               conda-forge
functools32:                   3.2.3.2-py27_1        conda-forge
geopandas:                     0.3.0-py27_0          conda-forge
geos:                          3.6.2-1               conda-forge
geotiff:                       1.4.2-1               conda-forge
giflib:                        5.1.4-0               conda-forge
hdf4:                          4.2.13-0              conda-forge
hdf5:                          1.10.1-1              conda-forge
icu:                           58.2-0                conda-forge
intel-openmp:                  2018.0.0-h8158457_8              
jpeg:                          9b-2                  conda-forge
json-c:                        0.12.1-0              conda-forge
kealib:                        1.4.7-4               conda-forge
krb5:                          1.14.2-0              conda-forge
libcxx:                        5.0.0-0               conda-forge
libdap4:                       3.18.3-2              conda-forge
libgdal:                       2.1.4-9               conda-forge
libgfortran:                   3.0.1-h93005f0_2                 
libiconv:                      1.15-0                conda-forge
libnetcdf:                     4.4.1.1-10            conda-forge
libpng:                        1.6.34-0              conda-forge
libpq:                         9.6.3-0               conda-forge
libspatialindex:               1.8.5-1               conda-forge
libspatialite:                 4.3.0a-19             conda-forge
libssh2:                       1.8.0-2               conda-forge
libtiff:                       4.0.9-0               conda-forge
libxml2:                       2.9.7-0               conda-forge
llvmdev:                       5.0.0-default_0       conda-forge
matplotlib:                    2.1.2-py27_0          conda-forge
mkl:                           2018.0.1-hfbd8650_4              
munch:                         2.2.0-py27_0          conda-forge
ncurses:                       5.9-10                conda-forge
numpy:                         1.14.0-py27h8a80b8c_1            
openjpeg:                      2.3.0-2               conda-forge
openssl:                       1.0.2n-0              conda-forge
pandas:                        0.22.0-py27_0         conda-forge
pcre:                          8.39-0                conda-forge
pip:                           9.0.1-py27_1          conda-forge
proj4:                         4.9.3-5               conda-forge
psycopg2:                      2.7.3.2-py27_0        conda-forge
pyparsing:                     2.2.0-py27_0          conda-forge
pyproj:                        1.9.5.1-py27_0        conda-forge
pysal:                         1.14.3-py27_0         conda-forge
python:                        2.7.14-4              conda-forge
python-dateutil:               2.6.1-py27_0          conda-forge
pytz:                          2017.3-py_2           conda-forge
readline:                      7.0-0                 conda-forge
rtree:                         0.8.3-py27_0          conda-forge
scipy:                         1.0.0-py27h793f721_0             
setuptools:                    38.4.0-py27_0         conda-forge
shapely:                       1.6.4-py27_0          conda-forge
singledispatch:                3.4.0.3-py27_0        conda-forge
six:                           1.11.0-py27_1         conda-forge
sqlalchemy:                    1.2.1-py27_0          conda-forge
sqlite:                        3.20.1-2              conda-forge
ssl_match_hostname:            3.5.0.1-py27_1        conda-forge
subprocess32:                  3.2.7-py27_0          conda-forge
tk:                            8.6.7-0               conda-forge
tornado:                       4.5.3-py27_0          conda-forge
wheel:                         0.30.0-py27_2         conda-forge
xerces-c:                      3.2.0-0               conda-forge
xz:                            5.2.3-0               conda-forge
zlib:                          1.2.11-0              conda-forge
4

2 回答 2

1

在mac上的终端运行brew install spatialindex解决了这个问题。

于 2019-09-15T23:19:02.027 回答
1

我从下面的代码解决了这个问题。

sudo apt-get install automake
sudo apt-get install libtool
sudo apt-get install pkg-config
curl -L https://github.com/libspatialindex/libspatialindex/archive/1.8.5.tar.gz | tar xz
cd libspatialindex-1.8.5/
./autogen.sh 
./configure
make
sudo make install
sudo ldconfig

希望它有效。

于 2019-06-15T03:25:58.533 回答