系统:Mac OSX
我是Python的新用户,目前正在探索GIS。 尝试使用geopandas读取形状文件但是我得到: OSError:找不到libspatialindex_c库文件
正常使用Python 3.7,但由于此上有geopandas存在依赖性问题,因此遵循此建议在Python2上运行。
我在这里做的是使用mac终端,用python2创建新环境并在那里安装了geopandas并尝试读取shape文件。
conda create -n mytest python = 2.7 geopandas -c conda-forge
source activate mytest
导入geopandas
geopandas.read_file(' Random_points_twitter.shp&#39)
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
在带有新笔记本的浏览器上,尝试导入并读取形状文件(类似于我在终端中所做的),但它给了我这个错误:
OSError Traceback(最近一次调用最后一次) in() ----> 1导入geopandas
/Users/rldy/anaconda/lib/python2.7/site-packages/geopandas/ init .py in() ----> 1来自geopandas.geoseries导入GeoSeries 2来自geopandas.geodataframe导入GeoDataFrame 3 4来自geopandas.io.file导入read_file 5来自geopandas.io.sql import read_postgis
/Users/rldy/anaconda/lib/python2.7/site-packages/geopandas/geoseries.py in() 10 11来自geopandas.plotting import plot_series ---> 12来自geopandas.base导入GeoPandasBase,_series_unary_op,_CoordinateIndexer 13 14
/Users/rldy/anaconda/lib/python2.7/site-packages/geopandas/base.py in() 12 13尝试: ---> 14来自rtree.core导入RTreeError 15 HAS_SINDEX = True 16除了ImportError:
/Users/rldy/anaconda/lib/python2.7/site-packages/rtree/ init .py in() ----> 1来自.index import Rtree 2 3来自.core import rt 4 5 版本 =' 0.8.3'
/Users/rldy/anaconda/lib/python2.7/site-packages/rtree/index.py in() 3导入pprint 4 ----> 5来自。进口核心 6个导入ctypes 7尝试:
/Users/rldy/anaconda/lib/python2.7/site-packages/rtree/core.py in() 123 124如果lib_name为None: - > 125引发OSError("找不到libspatialindex_c库文件") 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
答案 0 :(得分: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
希望它能起作用。
答案 1 :(得分:0)
在Mac上的终端中运行brew install spatialindex
解决了该问题。