Opened 6 years ago
Closed 6 years ago
#7118 closed defect (fixed)
Python bindings build can't always find headers
Reported by: | nikhaldi | Owned by: | hobu |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | PythonBindings | Version: | svn-trunk |
Severity: | normal | Keywords: | |
Cc: |
Description
I ran into situations where setup.py cannot build the Python package because it cannot find GDAL headers. For example with the standard libgdal-dev package in Ubuntu 16.04, which is probably a pretty common situation.
Here's a full example of how to reproduce it (using docker since that makes it easy to reproduce this problem from scratch):
$ docker pull ubuntu:16.04 16.04: Pulling from library/ubuntu Digest: sha256:506e2d5852de1d7c90d538c5332bd3cc33b9cbd26f6ca653875899c505c82687 Status: Image is up to date for ubuntu:16.04 $ docker run -it ubuntu:16.04 /bin/bash root@83a8ac258e08:/# apt-get update -y [output omitted] root@7e01b8589a75:/# apt-get -y install gdal-bin libgdal-dev [output omitted] root@7e01b8589a75:/# gdal-config --version 1.11.3 root@7e01b8589a75:/# gdal-config --cflags -I/usr/include/gdal root@7e01b8589a75:/# apt-get -y install python-pip [output omitted] root@7e01b8589a75:/# pip install gdal==1.11.2 Collecting gdal==1.11.2 Downloading GDAL-1.11.2.tar.gz (477kB) 100% |################################| 481kB 2.6MB/s Building wheels for collected packages: gdal Running setup.py bdist_wheel for gdal ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-KKYLuZ/gdal/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpYqS8cTpip-wheel- --python-tag cp27: running bdist_wheel 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 creating 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/gdalnumeric.py -> 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/gdal_array.py -> build/lib.linux-x86_64-2.7/osgeo copying osgeo/ogr.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/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 cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++ extensions/gdal_wrap.cpp:2855:22: fatal error: cpl_port.h: No such file or directory compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Failed building wheel for gdal Running setup.py clean for gdal Failed to build gdal 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-KKYLuZ/gdal/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-cnomAN-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 creating 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/gdalnumeric.py -> 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/gdal_array.py -> build/lib.linux-x86_64-2.7/osgeo copying osgeo/ogr.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/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 cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++ extensions/gdal_wrap.cpp:2855:22: fatal error: cpl_port.h: No such file or directory 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-KKYLuZ/gdal/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-cnomAN-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-KKYLuZ/gdal/ You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
The libgdal-dev package installs headers in /usr/include/gdal which "gdal-config --cflags" correctly reports but the setup.py script does not consider that.
The same problem reproduces with most recent versions of GDAL packaged for Ubuntu (pulled from https://launchpad.net/~ubuntugis/+archive/ubuntu/ubuntugis-unstable).
The internet reveals various people who have run into this (e.g., https://gis.stackexchange.com/questions/28966/python-gdal-package-missing-header-file-when-installing-via-pip).
A fix to setup.py should be relatively easy, I'll try to provide one.
I have a proposed fix at https://github.com/OSGeo/gdal/pull/258 now