在 Python27 Software Collection 中安装 gdal python 包

在 Python27 Software Collection 中安装 gdal python 包

我有一个 Centos 6.6 虚拟机Python 2.7 SCL。我安装了 gdal 和 gdal-devel。

如果我启动 sclsudo scl enable python27 bash并执行 apip install gdal它会失败:

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I/opt/rh/python27/root/usr/include/python2.7 -I. -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-2.7/extensions/gdal_wrap.o

extensions/gdal_wrap.cpp:2855:22: error: cpl_port.h: No such file or directory

extensions/gdal_wrap.cpp:2856:24: error: cpl_string.h: No such file or directory

extensions/gdal_wrap.cpp:2857:27: error: cpl_multiproc.h: No such file or directory

extensions/gdal_wrap.cpp:2858:22: error: cpl_http.h: No such file or directory

extensions/gdal_wrap.cpp:2860:18: error: gdal.h: No such file or directory

extensions/gdal_wrap.cpp:2861:23: error: gdal_priv.h: No such file or directory

extensions/gdal_wrap.cpp:2862:22: error: gdal_alg.h: No such file or directory

extensions/gdal_wrap.cpp:2863:24: error: gdalwarper.h: No such file or directory

extensions/gdal_wrap.cpp:4870:22: error: gdalgrid.h: No such file or directory

extensions/gdal_wrap.cpp:2880: error: ‘CPLErrorHandler’ does not name a type

extensions/gdal_wrap.cpp:2883: error: expected initializer before ‘PythonBindingErrorHandler’

extensions/gdal_wrap.cpp:2755: warning: ‘swig_module’ defined but not used

error: command 'gcc' failed with exit status 1

在 /opt/rh/python27/root/usr/include/ 中获取 gdal 或使 pip 将 gcc 指向 /usr/include/ 的正确方法是什么?

答案1

我通过修改使其在虚拟环境中工作这个方法

有两个问题。首先,我必须专门使用 gdal 模块版本 1.9.1。 1.10.0 和 1.11.0 无法与核心 gdal 库的 1.9.2 版一起使用,这是 redhat 附带的。其次,我必须将 -I/usr/include/gdal 传递给 gcc。顺序如下:

# you might need to do a sudo -s if your virtualenv is owned by root.
scl enable python27 bash
cd $VIRTUENV_ROOT
source bin/activate
pip install --no-install gdal==1.9.1
cd build/gdal
python setup.py build_ext \
  --gdal-config=/usr/bin/gdal-config \
  --include-dirs=/usr/include/gdal/
python setup.py install

虚拟环境并不是绝对必要的,但我不知道全局 python 构建文件夹在哪里。

相关内容