[GIS] Shapely in Spyder for Python 2.7

geosimportpythonshapely

I already use another library "shapefile", which was easy to import. However I just installed shapely 1.3.3 for windows (which still has an installer) and cannot import it. I tried it the same way as with the other library (import shapely) after the installation, but it only throws the error:

ImportError: No module named shapely

Edit: I run Python-2.7.9 and have GEOS installed. If I try "import shapely" I get the error "No module named shapely" and if I don't do it, I get this:

Point=(0,0)
print Point.geom_type

AttributeError: 'tuple' object has no attribute 'geom_type'

Can somebody resolve this? It should be a legit command. I do not understand what could be wrong.

Edit: It seems like shapely is not recognized by Python, eventhough it definitely is installed. I tried using another version of Shapely and got the same result. I really need a Shapely function to continue working on a work project but cannot figure out why it doesn't work. I also tried installing it with pip, which wasn't of any use as well.

Best Answer

You can check where Python is looking for modules using:

import sys

for s in sys.path:
    print s

This will generally be a list of directories. If your Shapely module was not installed to one of these then Python wont be able to "see" it.

In this case you will either have to re-install it to one of the shown directories or make its location known to Python. You can do this in the code itself:

import sys

# Add shapely's parent directory to the list to be searched
sys.path.append(r'YOUR_SHAPELY_PARENT_DIRECTORY')

# Now import Shapely
import shapely

You will have to include the above within each Python file in which you import Shapely. For a more permanent solution you can set the PYTHONPATH environment variable with search paths you want to always include. For more information check out the sys module, particularly sys.path.