PyGame Installation Mac OS X
Solution 1
This is the best method I've found for installing on OS X (and works with Python 3):
Step 1: Install XCode command line tools
XCode is the tool from Apple for creating Mac and iOS applications. It can be installed from the App Store (it’s free). When it’s finished, type the following at the command line:
$ xcode-select --install
Step 2: Install Homebrew (http://brew.sh)
Homebrew is a tool to easily install all kinds of software from the command line. It saves you having to go to a bunch of different sites and download lots of individual installers. Copy and paste this on the command line:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
and follow the directions. You’ll also need to install Homebrew Cask (http://caskroom.io):
$ brew install caskroom/cask/brew-cask
Step 3: Install the rest of the software
Now we can start installing all the requirements for Pygame. Just type the following commands one at a time and let the computer do its thing:
$ brew cask install xquartz
$ brew install python3
$ brew install python
$ brew linkapps python3
$ brew linkapps python
$ brew install git
$ brew install sdl sdl_image sdl_ttf portmidi libogg libvorbis
$ brew install sdl_mixer --with-libvorbis
$ brew tap homebrew/headonly
$ brew install smpeg
$ brew install mercurial
$ pip3 install hg+http://bitbucket.org/pygame/pygame
Step 4: See if it works!
Now we can see if it works. Run Python from the command line:
$ python3
and try loading Pygame:
>>> import pygame
If you don’t see an error message, you’re all set!
Solution 2
How to install PyGame on the Mac OS X El Capitan 10.11.1
- Install Anaconda 2.7
- Get the SDL Framework run dmg and copy to /Library/Frameworks
- brew install sdl note you need Homebrew installed
- Ensure you have XCODE and latest Command Line Tools for XCODE
-
Open Terminal and run
conda update conda
conda create -n py27 python
source activate py27
conda install binstar
conda install anaconda-client
conda install -c https://conda.binstar.org/erik pyobjc
conda install -c https://conda.binstar.org/erik pyobjc-core
conda install -c https://conda.binstar.org/erik pyobjc-framework-Cocoa
conda install -c https://conda.binstar.org/erik pyobjc-framework-Quartz
conda install numpy
conda install pyopengl
brew install homebrew/python/pygame
There are some specific instructions to follow after brew is run.
You will also need to create a sitecustomize.py file in /Users/toasteez/anaconda/envs/pygame/lib/python2.7/site-packages
I added the env to my Pycharm Project Interpreter and it seems fine.
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I downloaded Python 2.7.10 and I wanted to install pygame. I downloaded the DMG from pygame's website (Version 1.9.1) and installed it. To test if pygame was installed properly, I opened IDLE and entered the command
import pygame
just for the following error to return:File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module> from pygame.base import * ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
I'm running OSX Yosemite version 10.10.3, does anyone know how to fix this issue and properly install pygame without any issues>
-
ctrl-alt-delete over 8 yearsThere is an issue with the SDL of which I think happens because Anaconda Python is 64Bit and SDL may only support 32bit Python
-
ctrl-alt-delete over 8 yearsI don't want to use Homebrew or Brew. But thanks for the tip.
-
Chris over 8 yearsCan I ask why? Homebrew is a really useful tool and makes it a lot easier to install dev tools and libraries on OS X. Just curious.
-
ctrl-alt-delete over 8 yearsI just like the Anaconda / Conda Eco system. It keeps everything in one place.
-
Vladimir Vlasov almost 7 yearsLooks like
brew install caskroom/cask/brew-cask
doesn't work. It's better to usebrew tap caskroom/cask
.