{"id":698,"date":"2014-03-12T23:01:28","date_gmt":"2014-03-13T03:01:28","guid":{"rendered":"http:\/\/wcarss.ca\/log\/?p=698"},"modified":"2014-03-12T23:01:28","modified_gmt":"2014-03-13T03:01:28","slug":"installing-pygame-on-max-os-x-10-8-5-mountain-lion","status":"publish","type":"post","link":"https:\/\/wcarss.ca\/log\/2014\/03\/installing-pygame-on-max-os-x-10-8-5-mountain-lion\/","title":{"rendered":"Installing pygame on Max OS X 10.8.5 Mountain Lion"},"content":{"rendered":"<p><span style=\"line-height: 1.6;\">I first tried to follow\u00a0<\/span><a style=\"line-height: 1.6;\" title=\"a pretty little guide that didn't quite work for me\" href=\"http:\/\/jamesfriend.com.au\/installing-pygame-python-mac-os-108-mountain-lion\">this guide<\/a><span style=\"line-height: 1.6;\">, which\u00a0did install pygame but left it spitting this kind of error when I tried to actually use it:<\/span><\/p>\n<pre><code>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 259'<\/code><\/pre>\n<p>That sucked, so here is an alternative.<\/p>\n<p>I assume that you already have a <a title=\"how to tell which you have\" href=\"http:\/\/stackoverflow.com\/questions\/1405913\/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode-on-os\">64-bit version of Python 2.7.2+<\/a>\u00a0along with\u00a0<a title=\"how to install pip\" href=\"http:\/\/www.pip-installer.org\/en\/latest\/installing.html\">pip<\/a> and <a title=\"how to get and use virtualenvs\" href=\"http:\/\/docs.python-guide.org\/en\/latest\/dev\/virtualenvs\/\">virtualenv<\/a>, and the <a title=\"I pulled this link from that guide above. It was really good!\" href=\"http:\/\/docwiki.embarcadero.com\/RADStudio\/XE4\/en\/Installing_the_Xcode_Command_Line_Tools_on_a_Mac\">XCode Command Line Tools<\/a>.<\/p>\n<p>First, install XQuartz. It is an X11 server, which SDL needs, and which is no longer in OSX. The official version is\u00a0<a title=\"The official website pointed to by the support.apple.com docs.\" href=\"http:\/\/xquartz.macosforge.org\/landing\/\">here<\/a>, but that site is flaky, so I downloaded it from CNET(<a title=\"it should start downloading automatically\" href=\"http:\/\/download.cnet.com\/XQuartz-X11\/3001-2094_4-10912185.html\">direct\u00a0download link<\/a>). After running that dmg, you should log out and back in, then start the\u00a0x server (e.g. cmd+space, &#8216;xquartz&#8217;, enter). If it shows up in your dock, you&#8217;re good.<\/p>\n<p>Next, we install SDL. \u00a0Download the OSX 10.5 runtime library dmg from <a title=\"sdl downloads page\" href=\"http:\/\/libsdl.org\/download-1.2.php\">libsdl.org<\/a>\u00a0and run it.\u00a0Inside, just find the SDL.framework folder and copy it into \/Library\/Frameworks &#8212; you&#8217;ll probably need to enter your password.<\/p>\n<p>Next set the environment variables needed to perform the compilation:<\/p>\n<pre><code>export CC='\/usr\/bin\/gcc'\r\nexport CFLAGS='-isysroot \/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/MacOSX.platform\/Developer\/SDKs\/MacOSX10.8.sdk -I\/opt\/X11\/include -arch i386 -arch x86_64'\r\nexport LDFLAGS='-arch i386 -arch x86_64'\r\nexport ARCHFLAGS='-arch i386 -arch x86_64'<\/code><\/pre>\n<p>(thanks to james friend for writing the guide I linked above, which this is directly lifted from). The effects of these lines will only last as long as your terminal is open, so don&#8217;t close it until you get things working.<\/p>\n<p>You can now make a virtualenv, activate it, and install pygame:<\/p>\n<pre><code>virtualenv game-env\r\n. game-env\/bin\/activate\r\npip install pygame<\/code><\/pre>\n<p>It should say something like:<\/p>\n<pre><code>\r\nDownloading\/unpacking pygame\r\n  Downloading pygame-1.9.1release.tar.gz (2.1MB): 2.1MB downloaded\r\n  Running setup.py egg_info for package pygame\r\n\r\n    WARNING, No \"Setup\" File Exists, Running \"config.py\"\r\n    Using Darwin configuration...\r\n\r\n    Hunting dependencies...\r\n    Framework SDL found\r\n    Framework SDL_ttf not found\r\n    Framework SDL_image not found\r\n    Framework SDL_mixer not found\r\n    Framework smpeg not found\r\n    PNG     : found\r\n    JPEG    : found\r\n    SCRAP   : not found\r\n    PORTMIDI: not found\r\n    Framework CoreMidi found\r\n\r\n    If you get compiler errors during install, doublecheck\r\n    the compiler flags in the \"Setup\" file.\r\n\r\n    Continuing With \"setup.py\"<\/code><\/pre>\n<p>As long as &#8220;SDL&#8221; was found, you&#8217;re in a good spot.<\/p>\n<p>If you get an error that looks like this at the very end:<\/p>\n<pre><code>\/Library\/Frameworks\/SDL.framework\/Versions\/Current\/Headers\/SDL_syswm.h:58:10: fatal error: 'X11\/Xlib.h' file not found\r\n\r\n#include &lt;X11\/Xlib.h&gt;\r\n\r\n         ^\r\n\r\n1 error generated.\r\n\r\nerror: command 'clang' failed with exit status 1<\/code><\/pre>\n<p>then you&#8217;ve probably got to paste in the export lines listed above.<\/p>\n<p>If you get an error that looks like this at the end:<\/p>\n<pre><code>src\/_numericsurfarray.c:1100: warning: implicit declaration of function \u2018SDL_FreeSurface\u2019\r\n\r\nlipo: can't open input file: \/var\/folders\/5y\/shcnnkg970n53k9bvdvngw8w0000gp\/T\/\/cc1KHqyH.out (No such file or directory)\r\n\r\nerror: command '\/usr\/bin\/gcc' failed with exit status 1<\/code><\/pre>\n<p>with something like this near the top:<\/p>\n<pre><code>Installing collected packages: pygame\r\n  Running setup.py install for pygame\r\n    building 'pygame._numericsurfarray' extension\r\n    \/usr\/bin\/gcc -DNDEBUG -g -Os -Wall -Wstrict-prototypes -isysroot \/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/MacOSX.platform\/Developer\/SDKs\/MacOSX10.8.sdk -I\/opt\/X11\/include -pipe -arch i386 -arch x86_64 -I\/NEED_INC_PATH_FIX -I\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/include\/python2.7 -c src\/_numericsurfarray.c -o build\/temp.macosx-10.8-intel-2.7\/src\/_numericsurfarray.o\r\n    In file included from src\/_numericsurfarray.c:23:\r\n    src\/pygame.h:106:17: error: SDL.h: No such file or directory<\/code><\/pre>\n<p>then you&#8217;ll need to double check that you installed SDL properly. If you try this over and over and it doesn&#8217;t work, you might try to play with the export lines to find your copy of SDL, or follow the guide I linked at the start, which uses homebrew to install SDL.<\/p>\n<p>If things are messed up, you can always just delete the SDL.framework folder, delete your virtual environment, and start again.<\/p>\n<p>If things look good, try running a sample program like the following:<\/p>\n<pre><code>&gt;&gt;&gt; import pygame\r\n&gt;&gt;&gt; pygame.init()\r\n(4, 0)\r\n&gt;&gt;&gt; pygame.display.set_mode((640, 480))\r\n&lt;Surface(640x480x32 SW)&gt;\r\n&gt;&gt;&gt; pygame.quit()\r\n&gt;&gt;&gt; ^D<\/code><\/pre>\n<p>A screen should appear, and execution should finish cleanly. If that&#8217;s the case, you can make games with pygame. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I first tried to follow\u00a0this guide, which\u00a0did install pygame but left it spitting this kind of error when I tried to actually use it: Terminating app due to uncaught exception &#8216;NSInternalInconsistencyException&#8217;, reason: &#8216;Error (1000) creating CGSWindow on line 259&#8217; That sucked, so here is an alternative. I assume that you already have a 64-bit version [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/698"}],"collection":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/comments?post=698"}],"version-history":[{"count":10,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/698\/revisions\/708"}],"wp:attachment":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/media?parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/categories?post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/tags?post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}