{"id":965,"date":"2016-06-19T18:35:48","date_gmt":"2016-06-19T18:35:48","guid":{"rendered":"https:\/\/block.arch.ethz.ch\/blog\/?p=965"},"modified":"2016-07-07T07:46:50","modified_gmt":"2016-07-07T07:46:50","slug":"using-jonathan-shewchuks-triangle-library-with-python","status":"publish","type":"post","link":"https:\/\/block.arch.ethz.ch\/blog\/2016\/06\/using-jonathan-shewchuks-triangle-library-with-python\/","title":{"rendered":"Using Jonathan Shewchuk&#8217;s Triangle library with Python"},"content":{"rendered":"<p>Python Triangle is a python wrapper around Jonathan Richard Shewchuk\u2019s two-dimensional quality mesh generator and delaunay triangulator library. According to the Python Triangle docs, <a href=\"http:\/\/dzhelil.info\/triangle\/installing.html\" target=\"_blank\">installation is straightforward<\/a>. However, at least on my system, it didn&#8217;t work right out of the box. Luckily, the fix is quite simple.<\/p>\n<p><!--more--><\/p>\n<p>Triangle is available <a href=\"https:\/\/www.cs.cmu.edu\/~quake\/triangle.html\" target=\"_blank\">here<\/a>, and Python Triangle <a href=\"http:\/\/dzhelil.info\/triangle\/index.html\" target=\"_blank\">here<\/a>.<\/p>\n<p>The <code>easy_install<\/code> instructions didn&#8217;t work at all for me. Installing from the github clone did, but when importing <code>triangle<\/code> in python, i got the following error: <\/p>\n<pre class=\"toolbar:false;gutter:false\">\r\nImportError: cannot import triangle.core\r\n<\/pre>\n<p>Looking at the <code>triangle.__init__<\/code> file, the <code>core<\/code> module is imported from a shared object in the triangle package. StackOverflow has <a href=\"http:\/\/stackoverflow.com\/questions\/1099981\/why-cant-python-find-shared-objects-that-are-in-directories-in-sys-path\" target=\"_blank\">a post about importing dynamic linked libraries in Python<\/a> that explains why the import doesn&#8217;t work and how this can be resolved.<\/p>\n<p>Following the post, the problem is fixed by adding the triangle package to the <code>LD_LIBRARY_PATH<\/code> system variable. Do so by adding the following line to your <code>.profile<\/code>:<\/p>\n<pre class=\"brush:bash;toolbar:false;gutter:false\">\r\nexport LD_LIBRARY_PATH=\"path\/to\/triangle\/package:$LD_LIBRARY_PATH\"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python Triangle is a python wrapper around Jonathan Richard Shewchuk\u2019s 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&#8217;t work right out of the box. Luckily, the fix is quite simple.<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-965","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/comments?post=965"}],"version-history":[{"count":6,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/965\/revisions"}],"predecessor-version":[{"id":1021,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/posts\/965\/revisions\/1021"}],"wp:attachment":[{"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/media?parent=965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/categories?post=965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/block.arch.ethz.ch\/blog\/wp-json\/wp\/v2\/tags?post=965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}