I am trying to follow a tutorial from here http://qgistips.spatialthoughts.com/2012/12/find-neighbor-polygons-in-layer-in-qgis.html#more

I have downloaded the relevant python script and edited it as required. When I try to run the script using the Python console in QGIS >Plugins>Python Console I get the following error message.

ImportError: No module named shapely.wkb Start of relevant script

from PyQt4.QtCore import *
from shapely.wkb import loads
# Replace the below value with the field containing name or id of the feature
# For example, if your field is called name then change the line below to
# name_filed = 'name'

The module shapely.wkb is called on the second line of the script so the failure appears to be occurring as the second line of code is executed.

I have searched for a Python module with that name in Plugins>Fetch Python Modules Is this something that needs to be installed separately? From what I have read it should be installed with an installation of PostGis which I though got loaded when I used StackBuilder to install PostGreSQL.

Would installing installing Python 2.7.3 on my MAC Book Pro help?

2 Answers 2


You probably missed the step where you installed shapely. Aptitude (sudo apt-get install reference) is not compatible on Mac for many reasons, none I of which I will get into.

This Shapely For MAC

should get you there.

Also, I suspect you already have a version for python on your MAC, but it might be old. Shapely requires version 2.5 and you might be under it.

Install Python For MAC

will tell you how to test your version and how to upgrade.


If you use QGIS, you have Python 2.6 (Snow Leopard) or Python 2.7 (Lion,Mountain Lion) preinstalled (like in Linux) and it is theses versions that QGIS uses, not another one (no need to install other version of Python).The pythonic way to install a Python module like shapely is not with aptitude but with the solution of Paul Smith (Shapely For MAC) see also How to install shapely for python 2.6 (Mac) NOT 2.7?

  • I am running OSx Mountain Lion v 10.8.2 so if Python comes ready installed I don't understand why I have a problem !
    – nigellaw
    Commented Jan 20, 2013 at 18:36
  • because you must install shapely which is a pure Python module (in /Library/Python/2.7/site-packages/) and not a QGIS extension.
    – gene
    Commented Jan 20, 2013 at 19:16
  • Thank you, that makes more sense. I dont have this problem on a Wndows installation :)
    – nigellaw
    Commented Jan 20, 2013 at 19:35
  • because the Windows version of QGIS installs its own Python while in Mac OS X or Linux (which are Unix) QGIS use the default python installed with the OS.
    – gene
    Commented Jan 20, 2013 at 20:04
  • I must be missing something @gene. If QGIS uses the default python installed with the MAC OS why my problem? Or is it that QGIS doesn't know where to find the default python install in the MAC OS?
    – nigellaw
    Commented Jan 20, 2013 at 20:28

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.