Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python GDAL package missing header file when installing via pip

Tags:

I'm trying to install gdal from pip pip install gdal inside a virtual environment (Ubuntu). It fails because it cannot find cpl_port.h

extensions/gdal_wrap.cpp:2853:22: fatal error: cpl_port.h: No such file or directory compilation terminated 

However GDAL is installed correctly and the header file is located at /usr/include/gdal/cpl_port.h. Is there some environment variable for GDAL that needs to be set in order for pip to find the header files?

like image 845
Kevin Avatar asked Jul 04 '12 22:07

Kevin


People also ask

Can you install Gdal with pip?

gdal-utils: is the GDAL Python Utilities distribution. This is what you install. Its home page is https://pypi.org/project/gdal-utils/ . Install with pip install gdal-utils .

How do you add Gdal to Anaconda?

If you're using Anaconda3, the easiest way to install GDAL is to create a virtual environment through Anaconda Navigator, choosing Python 3.6 as the preferred version. Then, choose gdal from the list of uninstalled Python packages. This will install gdal version 2.1.

Is Gdal installed Linux?

GDAL is available in the default repositories of most popular Linux distributions and can be installed in the same way that packages in a Linux distribution are usually installed. CPLUS_INCLUDE_PATH and C_INCLUDE_PATH are necessary in order to include these corresponding libraries.


2 Answers

As suggested in the other thread, exporting some shell variables before running pip worked flawlessly. A path for *_INCLUDE_PATH can be found with gdal-config --cflags.

# GDAL library must have been installed sudo apt-get install libgdal-dev  # Set up pip and/or virtualenv stuff ...  # Now install Python binding for GDAL export CPLUS_INCLUDE_PATH=/usr/include/gdal export C_INCLUDE_PATH=/usr/include/gdal pip install GDAL 
like image 119
tomyun Avatar answered Oct 10 '22 04:10

tomyun


Tomyun's answer worked for me, with the proviso that you have to ensure that the version of GDAL-dev installed via apt-get matches the version being installed by pip.

For Ubuntu 14.04, the commands are:

# GDAL library must have been installed sudo apt-get install libgdal-dev  # Set up pip and/or virtualenv stuff ...  # Now install Python binding for GDAL export CPLUS_INCLUDE_PATH=/usr/include/gdal export C_INCLUDE_PATH=/usr/include/gdal pip3 install GDAL=1.10.0 
like image 29
Neil Smith Avatar answered Oct 10 '22 04:10

Neil Smith