用anaconda安装的python和各种包,linux和windows下都有,其中前者是2.7版本,而后者是3.x,用conda
install gdal安装gdal包之后,当运行from osgeo import
gdal时出现了各种问题。
windows下的问题
ImportError Traceback
(most recent call last)
in ()
---->
1from osgeo import gdal
~\Anaconda3\lib\site-packages\osgeo\__init__.py in
()
23
fp.close()
24 return
_mod
---> 25_gdal =
swig_import_helper()
26 del
swig_import_helper
27
else:
~\Anaconda3\lib\site-packages\osgeo\__init__.py
in swig_import_helper()
19
if fp is not
None:
20
try:
--->
21_mod =
imp.load_module('_gdal',
fp, pathname,
description)
22
finally:
23
fp.close()
~\Anaconda3\lib\imp.py
in load_module(name, file, filename,
details)
241 return
load_dynamic(name, filename,
opened_file)
242
else:
-->
243return
load_dynamic(name, filename,
file)
244 elif
type_ ==
PKG_DIRECTORY:
245 return
load_package(name,
filename)
~\Anaconda3\lib\imp.py
in load_dynamic(name, path, file)
341 spec
=
importlib.machinery.ModuleSpec(
342 name=name,
loader=loader, origin=path)
--> 343return
_load(spec)
344
345 else:
ImportError:
DLL load failed:
找不到指定的程序。
linux下的问题:
ImportError:
/home/loong1/anaconda2/lib/python2.7/site-packages/osgeo/../../../libgdal.so.20:
undefined symbol: TIFFReadRGBATileExt
其中windows下的解决方法国内已经有很多了,linux下的解决方法在这里:
https://stackoverflow.com/questions/27116402/python-gdal-undefined-symbol-gdalrasterbandgetvirtualmem
首先找到libgdal.so文件的位置,一般会放置在ananconda的lib文件夹中,然后在环境变量文件中加入:
export LD_PRELOAD=~/anaconda2/lib/libgdal.so
加载后即可