48

Here will be my sequence of command lines while trying to install gdal2.1 in a UBUNTU virtual machine. My virtual machine is a UBUNTU 16.04 LTS(64bit) I would need gdal2.1 and especially the Python bindings to work with it in python. The versionof python currently installed is 2.7.11+ and I installed numpy as I know that it is necessary for GDAL. now the command lines with the

Instructions I found in the Pypi page of GDAL2.1:

   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/

This was what I obtained. Consider that the VM has not other software or packages installed. I hope you can help me, using GDAL2.1 would be so important..

I have tried to ask for some suggestion in the GIS section but I had no answers so far

oz123
  • 27,559
  • 27
  • 125
  • 187
Antonio
  • 589
  • 1
  • 4
  • 5

4 Answers4

91

What worked for me is this: https://gis.stackexchange.com/a/193828/66527

Below, I copy that answer:

You can download GDAL 2.1 for Windows from GIS Internals. There is an installer and a portable version that doesn't require installation.

GDAL 2.1 is available for Ubuntu 16.04 from the UbuntuGIS-Stable PPA

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 

Note Ubuntu 16.04 comes with python 3.5 but uses python 2.7 as default

bsm
  • 556
  • 4
  • 6
Akhorus
  • 2,233
  • 20
  • 24
  • 3
    Works also for Ubuntu 14.04. – mrgloom May 05 '17 at 09:48
  • 1
    GDAL 2.1 is now available in ubuntugis-stable, so I thing you could change de first line sudo add-apt-repository ppa:ubuntugis/ppa – bsm Mar 14 '18 at 02:32
  • 1
    @bsm can you please edit the answer directly? Right now I don't have a context where to try it. – Akhorus Mar 21 '18 at 16:52
  • 1
    Note that this doesn't work for Conda users, because python-gdal and python3-gdal install into the system Python2 and Python3, not the Conda packages. For Conda users you probably need something like this: https://github.com/conda-forge/gdal-feedstock/issues/213#issuecomment-407449828 – Kyle McDonald Aug 20 '18 at 05:45
  • Doesn't work for me in Travis.ci https://travis-ci.org/Suor/django-cacheops/jobs/429893625 – Suor Sep 18 '18 at 06:00
  • Thanks, this worked for me on a cloud ubuntu 16.04 droplet. All the `pip` installations had been failing! – Nikhil VJ Apr 19 '19 at 04:47
  • Thanks, I can now use R INLA! – Yves Jun 26 '19 at 12:10
  • 2
    Thank you this worked fine. i added python3-gdal and work **sudo apt install gdal-bin python3-gdal python3-gdal** – NEBEZ Jan 17 '21 at 15:57
  • AttributeError: 'NoneType' object has no attribute 'people' – Stefan Aug 02 '23 at 13:08
13

"python-gdal" version 2.1.0 requires gdal version 2.1.0 . So the install of "libgdal1" version 1.11.3 isn't sufficient. Get gdal-2.1.0 : http://download.osgeo.org/gdal/2.1.0/gdal-2.1.0.tar.gz

And the ~43 dependencies : $ sudo apt-get build-dep gdal

Building and installing gdal-2.1.0 and the Python bindings :

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

... No issues here, using Ubuntu 16.04 - 64bits.


Knud Larsen
  • 5,753
  • 2
  • 14
  • 19
  • Oddly, I get an error - `gdal-2.1.0/.libs/libgdal.so: undefined reference to \`kmldom::SerializePretty(boost::intrusive_ptr const&)' ` - note the backtick before `kmldom`, but a single-quote after `const&)`. Previously I got two errors, because `libgdal.so` needed `png_set_longjmp_fn()` which requires `libpng` 1.4+ - the base install appeared to be libpng1.2.54, and when I installed `libpng16-dev` the second `make` error went away.. – GT. Jul 23 '16 at 03:50
2

Did you install python-dev ?

Before you install anything from source in Ubuntu, I suggest you take care of the build dependencies.

sudo apt-get build-dep python-gdal

Than try and run the installation.

oz123
  • 27,559
  • 27
  • 125
  • 187
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
user2682863
  • 3,097
  • 1
  • 24
  • 38
suni k
  • 11
  • 2