48

这是我尝试在 UBUNTU 虚拟机中安装 gdal2.1 时的命令行序列。我的虚拟机是 UBUNTU 16.04 LTS(64 位),我需要 gdal2.1,尤其是 Python 绑定才能在 python 中使用它。当前安装的python版本是2.7.11+,我安装了numpy,因为我知道GDAL需要它。现在命令行与

我在GDAL2.1的Pypi页面中找到的说明:

   antonio19812@antonio19812-VirtualBox:~$ sudo apt-get install libgdal1i

   libgdal1i is already the newest version (1.11.3+dfsg-3build2).

   antonio19812@antonio19812-VirtualBox:~$ sudo apt-get install libgdal1-dev

   libgdal1-dev is already the newest version (1.11.3+dfsg-3build2).

   antonio19812@antonio19812-VirtualBox:~$ sudo pip install gdal

   Collecting gdal Downloading GDAL-2.1.0.tar.gz (619kB) 100%   |████████████████████████████████| 624kB 247kB/s

   Installing collected packages: gdal

  Running setup.py install for gdal ... error


  Complete output from command /usr/bin/python -u -c "import setuptools, 


tokenize;file='/tmp/pip-build-_sHDUY/gdal/setup.py';


exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n',


'\n'), file, 'exec'))" install --record /tmp/pip-eOB65J-record/install-


record.txt --single-version-externally-managed --compile:


running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-2.7

copying gdal.py -> build/lib.linux-x86_64-2.7

copying ogr.py -> build/lib.linux-x86_64-2.7

copying osr.py -> build/lib.linux-x86_64-2.7

copying gdalconst.py -> build/lib.linux-x86_64-2.7

copying gdalnumeric.py -> build/lib.linux-x86_64-2.7

creating build/lib.linux-x86_64-2.7/osgeo

copying osgeo/gdal.py -> build/lib.linux-x86_64-2.7/osgeo

copying osgeo/gdalconst.py -> build/lib.linux-x86_64-2.7/osgeo

copying osgeo/osr.py -> build/lib.linux-x86_64-2.7/osgeo

copying osgeo/__init__.py -> build/lib.linux-x86_64-2.7/osgeo

copying osgeo/ogr.py -> build/lib.linux-x86_64-2.7/osgeo

copying osgeo/gdal_array.py -> build/lib.linux-x86_64-2.7/osgeo

copying osgeo/gnm.py -> build/lib.linux-x86_64-2.7/osgeo

copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-2.7/osgeo

running build_ext

building 'osgeo._gdal' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/extensions

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python2.7 -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-2.7/extensions/gdal_wrap.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
extensions/gdal_wrap.cpp:3085:22: fatal error: cpl_port.h: File o directory non 

esistente

compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-_sHDUY/gdal/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-eOB65J-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_sHDUY/gdal/

这是我得到的。考虑 VM 没有安装其他软件或软件包。我希望你能帮助我,使用 GDAL2.1 非常重要..

我试图在 GIS 部分寻求一些建议,但到目前为止我没有答案

4

4 回答 4

91

对我有用的是:https ://gis.stackexchange.com/a/193828/66527

下面,我复制那个答案:

您可以从GIS Internals下载适用于 Windows 的 GDAL 2.1 。有一个安装程序和一个不需要安装的便携式版本。

GDAL 2.1可用于来自UbuntuGIS-Stable PPA的 Ubuntu 16.04

sudo add-apt-repository -y ppa:ubuntugis/ppa
sudo apt update 
sudo apt upgrade # if you already have gdal 1.11 installed 
sudo apt install gdal-bin python-gdal python3-gdal # if you don't have gdal 1.11 already installed 

注意 Ubuntu 16.04 附带 python 3.5,但默认使用 python 2.7

于 2017-01-12T12:38:37.450 回答
13

“python-gdal” 2.1.0 版需要 gdal 2.1.0 版。所以安装“ libgdal1”版本 1.11.3 是不够的。获取 gdal-2.1.0:http: //download.osgeo.org/gdal/2.1.0/gdal-2.1.0.tar.gz

以及 ~43 个依赖项:$ sudo apt-get build-dep gdal

构建和安装 gdal-2.1.0 和 Python 绑定:

$ cd gdal-2.1.0/
$ ./configure --prefix=/usr/
$ make
$ sudo make install
$ cd swig/python/
$ sudo python setup.py install

...这里没有问题,使用 Ubuntu 16.04 - 64 位。


于 2016-05-19T06:00:34.370 回答
2

你安装了python-dev吗?

在 Ubuntu 中从源代码安装任何东西之前,我建议您注意构建依赖项。

sudo apt-get build-dep python-gdal

比尝试运行安装。

于 2016-05-18T11:00:03.817 回答
1
sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update

sudo apt-get update

sudo apt-get install gdal-bin

sudo apt-get install libgdal-dev

export CPLUS_INCLUDE_PATH=/usr/include/gdal

export C_INCLUDE_PATH=/usr/include/gdal

pip install --global-option=build_ext --global-option="-I/usr/include/gdal/" GDAL==2.0.1
于 2019-09-18T13:04:39.583 回答