Using Jonathan Shewchuk’s Triangle library with Python

share on google plus share on facebook share on twitter share on linkedin share via email

Python Triangle is a python wrapper around Jonathan Richard Shewchuk’s two-dimensional quality mesh generator and delaunay triangulator library. According to the Python Triangle docs, installation is straightforward. However, at least on my system, it didn’t work right out of the box. Luckily, the fix is quite simple.

Triangle is available here, and Python Triangle here.

The easy_install instructions didn’t work at all for me. Installing from the github clone did, but when importing triangle in python, i got the following error:

ImportError: cannot import triangle.core

Looking at the triangle.__init__ file, the core module is imported from a shared object in the triangle package. StackOverflow has a post about importing dynamic linked libraries in Python that explains why the import doesn’t work and how this can be resolved.

Following the post, the problem is fixed by adding the triangle package to the LD_LIBRARY_PATH system variable. Do so by adding the following line to your .profile:

export LD_LIBRARY_PATH="path/to/triangle/package:$LD_LIBRARY_PATH"

One Response to “Using Jonathan Shewchuk’s Triangle library with Python”

Leave a response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>