May 07, 2014 How to install Python3 + Pygame on mac os x - Mac computer GadgetHero. Mac vs PC - ROLE REVERSAL. Installing Python 3 and Pygame on OS X / Mac Platform - Duration.
- Open the Terminal.
- Install Homebrew.
- Enable the Xcode Command Line Tools, necessary for installing/compiling Homebrew:
xcode-select –install
- Then install Homebrew itself:
ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
- Install Python 2.7 with
brew install python
- Optionally you can also install Python 3 with
brew install python3
- Installing either of these with install pip and pip3 respectively, a package manager for Python.
- Install prerequisites for pygame:
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi mercurial
- Install pygame using
pip
withpip install hg+http://bitbucket.org/pygame/pygame
- Install numpy and matplotlib using
pip install numpy matplotlib
Then you can run Python scripts from the Terminal with python filename.py
.
Why use Homebrew? So when you install things you can easily remove and reinstall them if they break, remove them if they're misbehaving or you no longer need them, or update your packages whenever updates come out (you can do that with brew update
then brew upgrade
). It also makes installing all kinds of languages and things super easy.
Example
On windows
Navigate to http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame – an unofficial site providing windows binaries of open-source python packages for the official CPython distribution by Christoph Gohlke.
Download the appropriate pygame
.whl
file according to your installed python version. (The file is named something likepygame -
<pygame version> - <python version>
- win32.whl
)Run
inside your terminal, bash or consol.
Note: ifpip
is not found inPATH
try to runpython -m pip install your-pygame-package.whl
Check if you can import pygame as a python module
If you do not get an error, you have correctly installed pygame on your computer :)
On linux
Open your terminal and run
Note: This will install pygame for python2
Try to import pygame inside
If you do not get an error, you have correctly installed pygame on your linux system :)
On macOS
There are two ways to install it on mac:
Method 1
Pygame Download For Python 3.7
Go to the Pygame downloads page and download the mac installer. Run it, and it should install Pygame on your Mac.
Method 2
Install Homebrew:
Install Pygame On Mac
Then use Homebrew to install Python 2.7.12 and Pygame:
Now run Python in your terminal and try import pygame
. If it does not say anything, it's installed successfully.