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?
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 .
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With