I have a MAC OSX 10.7.5 and am trying to learn how to use QGIS. Following a couple of tutorials I came to know I have to install shapely.

I followed the instructions by the multi-cited http://tumblr.pauladamsmith.com, but I am afraid I did not understand neither how to start the installation.

I downloaded all the required files (i.e. GDAL 1.10 and its python package but did not move them in any particular directory - i.e. the complete GDAL framework seems to be installed into Library and the GDAL python package is still in the Download folder).

I did the following, thanks to the instructions of the link above:

MacBook-Pro-di-myname:Downloads myname$ cd /Users/myname/Downloads/GDAL-1.9.1 
MacBook-Pro-di-myname:GDAL-1.9.1 myname$ CFLAGS=`/Library/Frameworks/GDAL.framework/Versions/1.10/Programs/gdal-config --cflags`
MacBook-Pro-di-myname:GDAL-1.9.1 myname$ LDFLAGS=`/Library/Frameworks/GDAL.framework/Versions/1.10/Programs/gdal-config --libs` python setup.py install

but then that's what I get:

running install
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-3861.write-test'

The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:


Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment

For information on other options, you may wish to consult the
documentation at:


Please make the appropriate changes for your system and try again.

Where is this error coming from? What I am getting wrong? Since this error impedes me to continue I cannot follow the other instructions at the link above, so I am pretty stuck with my work and cannot continue.

I will appreciate any type of help: I am totally ignorant on Python language and programming as a whole, indeed it was an unexpected problem during my QGIS learning.

Thanks a lot Fra

2 Answers 2


Use Python default installer doing:

sudo easy-install shapely

You need write privileges to site-packages.

Other options:

  1. Install homebrew and perform your GDAL / Python / Shapely installation through there.
  2. Download the free (for academics?) version of Enthought Python. I believe it ships with shapely.
  • thanks for the answer. I already have homebrew within my terminal app. I tried to reply the commands there but the answer is always the same as above..Sorry for being so hard to learn programming language.
    – Francesco
    Commented Jun 6, 2013 at 15:40
  • @Francesco No worries. We have all started in the same place and had the same issues getting rolling. Good luck!
    – Jay Laura
    Commented Jun 6, 2013 at 15:43

It is a bit more complicated. If you want to use Shapely with the QGIS version of Kyng Chaos, this QGIS version uses the default Apple Python (modules in /Library/Python/2.7/site-packages/), not the Homebrew version, nor the Enthought Python, nor...(the other options are invalid).

The solution is, as Jay Laura says opening the terminal in the shapely folder

sudo python setup.py install

sudo because each folder in Mac OS X has permissions and the command allows a user to run programs with the security privileges of another user (normally the superuser or root). You have not the permissions to alter the folder /Library/, it belongs to root

The final result is:

The C extension could not be compiled, speedups are not enabled.
Plain-Python installation succeeded.

and in the Python Shell (Terminal.app) or in the QGIS Python console:

>>> import shapely
>>> shapely.__version__

and you use the Plain-Python version of shapely without the speedups:

>>> import shapely.speedups
>>> print shapely.speedups.available

Why ?

If you do not know the UNIX part of MAC OS X and Python, it will difficult to understand. The solution given by Paul Smith is specific, it allows you to install a Shapely version with speedups enabled (by the GEOS C library and not the GDAL library,unnecessary here). With a C file you need a C compiler (gcc or other) which is no more installed by default in Lion (yes in Snow Leopard), even with easy_install or pip, the two ways to install a Python module.

You only need to download and install the Command Line Tools available from withing XCode, You can get it freely (XCode) from App Store, look at the end of command line tools or, easier, you can download/install the OSX GCC Installer of kennethreitz (command line tools without XCode).

With the KyngChaos version of QGIS, this GEOS library is already installed in /Library/Frameworks/GEOS.framework/ (an the GDAL module in /Library/Frameworks/GDAL.framework) and the flags

LDFLAGS=`/Library/Frameworks/GEOS.framework/Versions/3/unix/bin/geos-config --libs` 
CFLAGS=`/Library/Frameworks/GEOS.framework/Versions/3/unix/bin/geos-config --cflags` 

are only the paths of the C GEOS libraries in /Library/Frameworks/GEOS.framework/ used by the script setup.py and the flags (LDFLAGS = the folder lib and CFLAG, the folder include).

enter image description here

Once the compilers installed, you can install the shapely module with the solution given by Paul Smith and the result is:

>>> import shapely.speedups
>>> print shapely.speedups.available

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.