Installing Pyglet in Mac OS X

Pyglet is a common requirement for many Python applications, a major one being Cocos2D.

But it doesn’t work out of the box. Running a Pyglet application will result in the following error:

OSError: dlopen(/System/Library/Frameworks/QuickTime.framework/QuickTime, 6): no suitable image found.  Did find:

/System/Library/Frameworks/QuickTime.framework/QuickTime: mach-o, but wrong architecture

/System/Library/Frameworks/QuickTime.framework/QuickTime: mach-o, but wrong architecture

The following are the steps to take to get Pyglet and PyObjc installed on OS-X (tested with 10.7 Lion).

Pyglet 1.1 uses the Carbon framework, but this is not compatible with 64-bit Python installs. The Pyglet 1.2 branch has been modified to use Quartz, but no releases of this branch have seen the light of day (sigh). We must instead install Pyglet from the Mercurial repository.

The Quartz bindings require the use of PyObjc but the latest versions do not work with Pip. The patches to PyObjc’s setup.py that I’ve seen on the internet do not work for me. The following is the only method I’ve had work.

Remove any existing Pyglet install

pip uninstall pyglet

Install Pyglet from the repository

pip install hg+https://pyglet.googlecode.com/hg/

Edit: The following is no longer needed

We need to install PyObjc for the new Pyglet Quartz API. But PyObjc is horribly broken and the latest version does not install with Pip or easy_install.

We must instead install an older version.

pip install pyobjc==2.2

You should now have a working Pyglet installation.

18 Responses to “Installing Pyglet in Mac OS X”

  1. Winston Says:

    Thank you for posting this. I’ve been trying to get Pyglet to run on Lion and having a terrible time.

  2. Worked like a charm. Thanks for posting this.

  3. what is pip i keep getting an error that is is an unknown command

  4. Hi, I’m struggling to make “pip install pyobjc==2.2” but keep on getting some compiler error which is mentioned at “http://trac.macports.org/ticket/35325”.

    I found some solution like have “arch -i386 python” command to force the python run in 32 bit mode, which seems to work alright now.

    BTW, the pyglet 1.2alpha has supported python 64 bit system. I’ve tried it, but there is some weird problem, so I don’t keep on figuring.

    • You shouldn’t need PyObjC for the latest versions of Pyglet.
      Try installing directly from pip (pip install pyglet).
      If not, try installing, via Mercurial, directly from their repository (pip install hg+https://code.google.com/p/pyglet/).

      Let me know how that goes =)

      Cheers,
      Adam

  5. MacMonk Says:

    After downloading the .tar file and installation i had the same problem….

    solved by terminal:
    defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

    works now like a charm!

  6. James Says:

    Thank you so much!

  7. Fabian Mueller Says:

    Thanks a lot!

  8. Thanks for posting this.

    I followed all steps but still receive the error message you posted above:

    OSError: dlopen(/System/Library/Frameworks/QuickTime.framework/QuickTime, 6): no suitable image found. Did find:
    /System/Library/Frameworks/QuickTime.framework/QuickTime: mach-o, but wrong architecture
    /System/Library/Frameworks/QuickTime.framework/QuickTime: mach-o, but wrong architecture

    I’m working on OSX 10.9.2 with 64-bit Python 2.7.6.
    The command “import pyglet” works, but “import piglet.gl” fails. Do you have any idea?

    • I’m not sure. I’ve seen that before. I think it was to do with 64bit python trying to use 32bit libs. Not sure why that’s the case here.

      Are you using the system python? Perhaps try a custom installation, I’ve had trouble with the default python previously and I don’t use it anymore.

      I’ve updated the post to remove the part about ‘pyobjc’ being required. Perhaps remove it and try again?

  9. Niels Says:

    These two steps worked for me:

    sudo pip uninstall pyglet
    sudo pip install hg+https://code.google.com/p/pyglet/

  10. […] Similar to above, installing my own did the trick best. I adapted the instructions I found on this site: https://twistedpairdevelopment.wordpress.com/2012/02/21/installing-pyglet-in-mac-os-x/ […]

  11. […] Similar to above, installing my own did the trick best. I adapted the instructions I found on this site: https://twistedpairdevelopment.wordpress.com/2012/02/21/installing-pyglet-in-mac-os-x/ […]

  12. dedicated mining server

    Installing Pyglet in Mac OS X | Twisted Pair Development

Leave a reply to Niels Cancel reply