I know there are a number of similar questions, but none of them have answers that allow me to use shapely in QGIS. In particular I am trying to install the Contour plugin, but this fails with the message "The plugin depends on some components missing on your system. You need to install the following Python module in order to enable it: shapely.geometry." The reason for this error is explained well here: How to install the Python module shapely for QGIS use?

These are the steps I have taken to solve the issue:

I first installed shapely via pip. This allowed me to import shapely in python 2.7, which is the default on my system, but installing the plug in still failed with the same error.

This question How to install shapely for python 2.6 (Mac) NOT 2.7? explained that qgis uses python 2.6, not 2.7, so I downloaded the tar file and did a sudo python2.6 setup.py install. Now I can import shapely in python 2.6 too.

But the installation of the plugin still fails with the same warning! I've also tried import shapely from the python console within QGIS, and there is "no module named shapely." Is there something I've overlooked?

EDIT. Thanks to the comments from gene below, it turns out that QGIS on Lion does use python 2.7, not 2.6. But still it doesn't work. It turns out though that I have a few different versions of 2.7:

From the terminal:

$ python
Python 2.7.2 (default, Mar 8 2012, 15:29:59)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

From the QGIS python console:

>>> import sys
>>> print sys.version
2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]

From the terminal again:

$ python2.7
Python 2.7.3 (default, Oct 22 2012, 06:12:32) 
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

So it seems that QGIS uses 2.7.1, Apple defaults to 2.7.2, and I also have 2.7.3. So I need to install shapely for 2.7.1?

  • QGIS uses the default Apple Python which is 2.6 in Snow Leopard but 2.7 in Lion and Mountain Lion. Try from shapely.geometry import Point in the Terminal.
    – gene
    Jun 25, 2013 at 6:32
  • @gene Yeah that works in the terminal in 2.7 (I use Lion).
    – EddyTheB
    Jun 25, 2013 at 15:17
  • @gene it doesn't work in 2.6. <code>import shapely</code> does, <code>import shapely.geometry</code> does not. (though that shouldn't matter right?)
    – EddyTheB
    Jun 25, 2013 at 15:20
  • In Lion, QGIS uses the défault Apple Python which is 2.7. You don't need the 2.6 version. If you use the défault Apple Python and shapely works in the terminal, then it should work in QGIS.
    – gene
    Jun 25, 2013 at 15:35
  • @gene And yet it doesn't... I've looked and I think QGIS is using a different version of 2.7, see my edit above. Do you know if I could install shapely to a particular version of 2.7? Thanks for your help.
    – EddyTheB
    Jun 25, 2013 at 16:19


Your Answer

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

Browse other questions tagged or ask your own question.