James Friend - python https://jamesfriend.com.au/tags/python en Installing Pygame for Python 3 on Mac OS Yosemite https://jamesfriend.com.au/installing-pygame-python-3-mac-os-yosemite <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>It's somewhat difficult to find instructions on how to successfully install Pygame for Python 3 on Yosemite. The front page of the Pygame website has a link which appears to point to installation instructions, but it is broken.</p> <p>Fortunately, someone posted <a href="http://pygame.org/wiki/macintosh">these instructions</a> on the Pygame wiki:</p> <p>Firstly, ensure you have the Apple Xcode command line tools installed:</p> <pre><code class="language-bash">xcode-select --install </code></pre> <p>Install XQuartz from <a href="http://xquartz.macosforge.org/landing/">http://xquartz.macosforge.org/landing/</a>. Restart your computer so the newly installed XQuartz is used.</p> <p>Make sure you have <a href="http://brew.sh/">homebrew</a> installed:</p> <pre><code class="language-bash">ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot; </code></pre> <p>Ensure the homebrew-installed binaries take precedence over system binaries in your <code>$PATH</code></p> <pre><code class="language-bash"># in ~/.bash_profile # Homebrew binaries now take precedence over Apple defaults export PATH=/usr/local/bin:$PATH </code></pre> <p>Use homebrew to install Python3 and Pygame dependencies, as well as Mercurial (<code>hg</code>), which we need to install Pygame from Bitbucket:</p> <pre><code class="language-bash">brew install python3 hg sdl sdl_image sdl_mixer sdl_ttf portmidi </code></pre> <p>Install Pygame from Bitbucket:</p> <pre><code class="language-bash">pip3 install hg+https://bitbucket.org/pygame/pygame </code></pre> </div></div></div><div class="field field-name-field-tags field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags:&nbsp;</div><div class="field-items"><div class="field-item even" rel="dc:subject"><a href="/tags/pygame" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">pygame</a></div><div class="field-item odd" rel="dc:subject"><a href="/tags/python" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">python</a></div></div></div> Sat, 20 Dec 2014 05:36:59 +0000 superuser 13 at https://jamesfriend.com.au Installing Pygame on Mac OS 10.8 Mountain Lion https://jamesfriend.com.au/installing-pygame-python-mac-os-108-mountain-lion <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>I decided to install and play around with Pygame today, mainly as an excuse to write some Python for a minor departure from all the Javascript/Coffeescript I've been writing lately. Unfortunately the process wasn't entirely frictionless, due to Pygame not yet accounting for Apple's move to XQuartz as the recommended X11 implementation for Mac OS as of 10.8 Mountain Lion. As a result I ran into some compilation errors while Pygame was building it's native extensions, which fortunately were not too hard to fix as I had some familiarity with changes to X11 on Mountain Lion.</p> <p><strong>TL;DR</strong> <a href="https://jamesfriend.com.au/installing-pygame-python-mac-os-108-mountain-lion#node_6_tldr">you need to set some environment variables before installing Pygame</a></p> <h3>What didn't work</h3> <p>Running <code>pip install pygame</code> would fail as follows:</p> <pre><code class="language-nohighlight">building 'pygame.display' extension cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -Ddarwin -I/Library/Frameworks/SDL.framework/Versions/Current/Headers -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/display.c -o build/temp.macosx-10.8-x86_64-2.7/src/display.o In file included from src/display.c:30: /Library/Frameworks/SDL.framework/Versions/Current/Headers/SDL_syswm.h:58:10: fatal error: 'X11/Xlib.h' file not found #include &lt;X11/Xlib.h&gt; ^ 1 error generated. error: command 'cc' failed with exit status 1 </code></pre> <p>While building the native extention 'pygame.display', Xlib.h (a particular X11 header, required by SDL) is not found, as XQuartz's <code>/opt/X11/include</code> directory has not been specified to search for headers.</p> <p>By setting some environment variables, we can configure the Pygame build process to build correctly. I found these in a few other blog posts, but they specified only <code>-arch i386</code> for CFLAGS, LDFLAGS and ARCHFLAGS, which allowed the build process to complete, but <code>import pygame</code> fails (when running 64bit Python):</p> <pre><code>&gt;&gt;&gt; import pygame Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/usr/local/lib/python2.7/site-packages/pygame/__init__.py", line 95, in &lt;module&gt; from pygame.base import * ImportError: dlopen(/usr/local/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find: /usr/local/lib/python2.7/site-packages/pygame/base.so: mach-o, but wrong architecture </code></pre> <h3><a id="node_6_tldr"></a>What actually got Pygame working</h3> <p>The environment variables (gcc flags) required to allow Pygame to correctly build fat binaries (for both 32bit and 64bit Python) are:</p> <pre><code>export CC='/usr/bin/gcc' export CFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/opt/X11/include -arch i386 -arch x86_64' export LDFLAGS='-arch i386 -arch x86_64' export ARCHFLAGS='-arch i386 -arch x86_64' </code></pre> <p>Then <code>pip install pygame</code> and <code>python -c 'import pygame'</code>. If no error is returned by Python, then you should now have a working installation of Pygame.</p> <h3>Additional details</h3> <p>I'm using homebrew-installed Python/pip, and I've set my $PATH with <code>/usr/local/bin</code> before the system-installed Python.</p> <p>If you haven't installed Python/pip via homebrew (you're using the system-installed Python), you would likely need to run <code>sudo pip install pygame</code>.</p> <p>If you're using another install method, such as easy_install, this fix should still work.</p> <p>Before running <code>pip install pygame</code>, I had also installed <a href="https://developer.apple.com/downloads/index.action">Command Line Tools for XCode</a> (<a href="http://docwiki.embarcadero.com/RADStudio/XE4/en/Installing_the_Xcode_Command_Line_Tools_on_a_Mac">walkthrough</a>), as well as <a href="http://xquartz.macosforge.org/landing/">XQuartz</a>, and the following homebrew packages: <code>brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi</code>.</p> <p>If homebrew fails to install <code>smpeg</code> you might need to do the following:</p> <pre><code class="language-bash">brew tap homebrew/headonly brew install --HEAD smpeg </code></pre> </div></div></div><div class="field field-name-field-tags field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags:&nbsp;</div><div class="field-items"><div class="field-item even" rel="dc:subject"><a href="/tags/python" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">python</a></div><div class="field-item odd" rel="dc:subject"><a href="/tags/homebrew" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">homebrew</a></div><div class="field-item even" rel="dc:subject"><a href="/tags/pygame" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">pygame</a></div><div class="field-item odd" rel="dc:subject"><a href="/tags/osx" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">osx</a></div><div class="field-item even" rel="dc:subject"><a href="/tags/mac" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">mac</a></div></div></div> Wed, 07 Aug 2013 08:34:15 +0000 James 6 at https://jamesfriend.com.au