main__.gdal_config_error: [Errno 2] No such file or directory: ‘gdal-config (gdal源码安装)

  • 装python3.6版本的gdal库,如果通过pip3安装,会报“main.gdal_config_error: [Errno 2] No such file or directory: 'gdal-config”这样的错误

  • gdal下载网址:http://download.osgeo.org/gdal

  • pip安装报错

$ pip install gdal
self.finalize_options()
      File "/tmp/pip-install-x4uercw8/gdal/setup.py", line 311, in finalize_options
        self.gdaldir = self.get_gdal_config('prefix')
      File "/tmp/pip-install-x4uercw8/gdal/setup.py", line 255, in get_gdal_config
        return fetch_config(option)
      File "/tmp/pip-install-x4uercw8/gdal/setup.py", line 154, in fetch_config
        raise gdal_config_error(e)
    __main__.gdal_config_error: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

  • 源码安装GDAL
$ wget http://download.osgeo.org/gdal/3.0.1/gdal-3.0.1.tar.gz

$ tar -xf gdal-3.0.1.tar.gz

$ cd gdal-3.0.1

$ ./configure --prefix=/home/share/wli/software/gdal/3.0.1

checking whether g++ supports C++11 features by default... no
checking whether g++ supports C++11 features with -std=c++11... no
checking whether g++ supports C++11 features with -std=c++0x... no
checking whether g++ supports C++11 features with +std=c++11... no
checking whether g++ supports C++11 features with -h std=c++11... no
configure: error: *** A compiler with support for C++11 language features is required.
(base) [wli@esg-dn1 gdal-3.0.1]$ which gcc
gcc is /usr/bin/gcc
(base) [wli@esg-dn1 gdal-3.0.1]$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
$ export PATH=/opt/gcc/8.3.0/bin/:$PATH
$ export LD_LIBRARY_PATH=/opt/gcc/8.3.0/lib64/:$LD_LIBRARY_PATH
$ gcc --version
gcc (GCC) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#############重新安装
$ ./configure --prefix=/home/share/wli/software/gdal/3.0.1
using ICONV_CPP_CONST=""
checking for PROJ >= 6 library... checking for proj_create_from_wkt in -lproj... no
checking for proj_create_from_wkt in -lproj... no
checking for internal_proj_create_from_wkt in -lproj... no
checking for internal_proj_create_from_wkt in -lproj... no
checking for internal_proj_create_from_wkt in -linternalproj... no
checking for internal_proj_create_from_wkt in -linternalproj... (cached) no
configure: error: PROJ 6 symbols not found

  • 报错configure: error: PROJ 6 symbols not found

  • 重新安装proj

  • 安装proj

$ wget https://github.com/OSGeo/PROJ/releases/download/6.2.0/proj-6.2.0.tar.gz
$ tar -xf proj-6.2.0.tar.gz
$ cd proj-6.2.0
$ ./configure --prefix=/home/share/wli/software/proj/6.2.0
checking for SQLITE3... configure: error: Package requirements (sqlite3 >= 3.7) were not met:

Requested 'sqlite3 >= 3.7' but version of SQLite is 3.6.20

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables SQLITE3_CFLAGS
and SQLITE3_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
$ export PKG_CONFIG_PATH=/home/share/wli/software/anaconda3c/lib/pkgconfig/:$PKG_CONFIG_PATH
$ ./configure --prefix=/home/share/wli/software/proj/6.2.0
$ make
$ make install
  • 生产变量重新测试安装
  • 重新安装gdal
$ ./configure --prefix=/home/share/wli/software/gdal/2.2.3
$ make
$ make install
  • 生产gdal环境变量
$ export PATH=/home/share/wli/software/gdal/2.2.3/bin/:$PATH
$ export LD_LIBRARY_PATH=/home/share/wli/software/gdal/2.2.3/lib/:$LD_LIBRARY_PATH
$ gdalinfo --help
  • 安装python版的gdal
cd /gdal-2.2.3/swig/python/
python setup.py build
python setup.py install

  • import gdal 会报:No module named _gdal
  • 生成指定变量 (gdal位置 显示安装结束前 Installed  /home/.../.egg
export PYTHONPATH=/home/share/wli/software/anaconda3c/lib/python3.7/site-packages/GDAL-2.2.2-py3.7-linux-x86_64.egg/osgeo/:$PYTHONPATH
  • 最后import gdal 测试
$ python
Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gdal
>>> 

作者:August________
链接:https://www.jianshu.com/p/b68057e25e85
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你喜欢

转载自blog.csdn.net/dou3516/article/details/111875619