{"id":731,"date":"2009-08-20T19:34:25","date_gmt":"2009-08-21T02:34:25","guid":{"rendered":"http:\/\/www.laurenwood.org\/anyway\/?p=731"},"modified":"2009-08-20T19:34:25","modified_gmt":"2009-08-21T02:34:25","slug":"python-and-the-mac","status":"publish","type":"post","link":"https:\/\/www.laurenwood.org\/anyway\/2009\/08\/python-and-the-mac\/","title":{"rendered":"Python and the&nbsp;Mac"},"content":{"rendered":"<p>I wanted to run a python pro\u00adgram on my Mac that was ori\u00adgin\u00adally writ\u00adten for Linux. Should work just fine, right? Well, not quite. Giv\u00aden it took quite a while to fig\u00adure out pre\u00adcisely what I needed, I\u2019m writ\u00ading it up for next time I need to do&nbsp;this.<\/p>\n<p>The first prob\u00adlem was an error mes\u00adsage triggered by the fail\u00adure of <code>import gtk<\/code>. The first assump\u00adtion was that I needed to install <code>python-gtk2<\/code>. For\u00adtu\u00adnately I\u2019d already installed <a href=\"http:\/\/developer.apple.com\/TOOLS\/Xcode\/\">XCode<\/a>. The easi\u00adest way to pull in pack\u00adages for oth\u00ader code is to install some port soft\u00adware; I picked <a href=\"http:\/\/www.macports.org\/\">Mac\u00adPorts<\/a>. Installing that does\u00adn\u2019t take too long, and it sets up the right depend\u00aden\u00adcies and envir\u00adon\u00adment vari\u00adables. Then comes the fun stuff, installing the oth\u00ader pack\u00adages. This takes some time, although being almost an auto\u00admat\u00adic pro\u00adcess makes it rel\u00adat\u00adively&nbsp;easy.<\/p>\n<p>The first thing to install was python_select, since I wanted to use a ver\u00adsion of python oth\u00ader than the default 2.4, then the right ver\u00adsion of python-gtk. For python 2.5, that&nbsp;meant<\/p>\n<pre><code>sudo port install python_select\npython_select python25\nsudo port install py25-gtk2<\/code><\/pre>\n<p>The pro\u00adgram still did\u00adn\u2019t run, with the same gtk error mes\u00adsage, so after vainly edit\u00ading path vari\u00adables etc, I looked at the source, and&nbsp;added&nbsp;<\/p>\n<pre><code>try:\n      import pygtk\n      pygtk.require(\"2.0\")\nexcept:\n      pass<\/code><\/pre>\n<p>before the <\/p>\n<pre><code>try:\n      import gtk<\/code><\/pre>\n<p>lines. This worked, and the pro\u00adgram moved onto the next miss\u00ading package.<\/p>\n<p>Repeat\u00ading for libxml2, and libxslt:<\/p>\n<pre><code>sudo port install py25-libxml2\nsudo port install py25-libxslt<\/code><\/pre>\n<p>and my pro\u00adgram finally worked.<\/p>\n<p>Check\u00ading what was installed where is easy: <code>port contents <em>package-name<\/em><\/code> where <em>pack\u00adage-name<\/em> is the name of the package.&nbsp;<\/p>\n<p>It looks like things work a lot bet\u00adter than they did just a few months ago, if all the art\u00adicles I found on how to get libxml to work with python on the Mac are any\u00adthing to go&nbsp;by.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to run a python pro\u00adgram on my Mac that was ori\u00adgin\u00adally writ\u00adten for Linux. Should work just fine, right? Well, not quite. Giv\u00aden it took quite a while to fig\u00adure out pre\u00adcisely what I needed, I\u2019m writ\u00ading it up for next time I need to do&nbsp;this. The first prob\u00adlem was an error mes\u00adsage \u2026 <a href=\"https:\/\/www.laurenwood.org\/anyway\/2009\/08\/python-and-the-mac\/\" class=\"more-link\">Con\u00adtin\u00adue read\u00ading<span class=\"screen-reader-text\"> \u201cPython and the&nbsp;Mac\u201d<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wp_typography_post_enhancements_disabled":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":""},"categories":[6],"tags":[89,90],"class_list":["post-731","post","type-post","status-publish","format-standard","hentry","category-technology","tag-macosx","tag-python"],"_links":{"self":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts\/731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/comments?post=731"}],"version-history":[{"count":8,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts\/731\/revisions"}],"predecessor-version":[{"id":739,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/posts\/731\/revisions\/739"}],"wp:attachment":[{"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/media?parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/categories?post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laurenwood.org\/anyway\/wp-json\/wp\/v2\/tags?post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}