I'm trying to instal the GDAL python package, preferably in a virtual environment, but when I try "pip install gdal", I get the following error:

extensions/gdal_wrap.cpp:3085:10: fatal error: 'cpl_port.h' file not found
    #include "cpl_port.h"

I have GDAL version 1.11.4 installed on my Mac. I installed it via Kyngchaos, and it is located at /Library/Frameworks/GDAL.framework/Versions/1.11/Resources/gdal

the cpl_port.h file is located in /Library/Frameworks/GDAL.framework/Versions/1.11/Headers

I've read several related topics but they're all on ubuntu and using older versions of pip that have commands like "--no-install" etc.

2 Answers 2


I found the answer on another thread with some minor tweaks:

(Adapted from Yellowcap's answer)

Make a virtual environment:

virtualenv env
source env/bin/activate
cd env

Download the GDAL package version you want, unzip it and cd into it:

pip download GDAL==1.11.2 (or whichever version you want)
tar -zxvf GDAL-1.11.2.tar.gz
cd GDAL-1.11.2

According to Yellowcap, you might need:

export CFLAGS=-Qunused-arguments export CPPFLAGS=-Qunused-arguments


python setup.py build_ext\

Build and install:

python setup.py build
python setup.py install
brew install gdal

python -m venv /path/to/new/virtual/environment --system-site-packages

I found that if you have installed gdal via brew (outside of your venv) you can use the gdal python bindings from the installation within your venv as long as your venv was created using the --system-site-packages flag.

This allows your virtual environment to access modules which were installed under your system's python installation.

Two things to note:

  • It is now possible for you to accidentally use system libraries now where you may not intended to.

  • If you are trying to install a library which has a dependency on a different version of GDAL, that installation will still fail.


  • This is only working if you create a new virtualenv and you don't necessarily want to do this. Another approach is just to link the brew recipes: brew link osgeo-gdal && brew link osgeo-gdal-python. gis.stackexchange.com/a/365232/142646
    – tupui
    Commented Jun 17, 2020 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.