LoginSignup
16
15

More than 5 years have passed since last update.

macOS High Sierraに Python3 + PyGame環境をインストール

Last updated at Posted at 2018-09-14

Python3 + PyGame 環境を Mac環境にインストールしたときの手順メモ

インストール手順は
ゲームを作りながら楽しく学べるPythonプログラミング を参考に進めた。

環境

  • macOS 10.13.6

1. Apple Store からXcodeをダウンロード、インストール

スクリーンショット 2018-09-05 11.28.38.png

5.3Gくらいあるからこれが時間がかかる。

2. ターミナルからXcodeコマンドラインツールをインストール

$ xcode-select --install

既にインストールされている旨のエラーが出た。

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Xcodeインストール時に一緒にインストールされたか?次に進める。

3. homebrewインストール

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

4. homebrew caskインストール

homebrew でdmg形式パッケージを扱うhomebrewの拡張ツール

$ brew install caskroom/cask/brew-cask
==> brew cask install caskroom/cask/brew-cask 
Error: Broken pipe @ io_write - <STDOUT>
Error: Cask 'brew-cask' is unavailable: '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/brew-cask.rb' does not exist.

公式 のインストール方法に倣うことに。

$ brew tap caskroom/cask

5. 残りソフトウェアをインストール

X11(xquartz)インストール

$ brew cask install xquartz

python3インストール

$ brew install python3

dupesインストール(不要)

$ brew install homebrew/dupes/tcl-tk でインストールするとのことだが、

Error: homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.

とエラーが出た。
調べてみると、 homebrew-core に統合されたらしい。

Today I’d like to announce Homebrew 1.2.0. The most significant change since 1.1.0 is that most Homebrew taps (package repositories) in the Homebrew GitHub organisation have been deprecated and the currently buildable software moved into Homebrew/homebrew-core.

なので、dupesのインストールは不要と判断。

gitインストール

$ brew install git

既にインストール済のため、スキップ。

SDL(Simple DirectMedia Layer), PortMidi, libogg, libvorbisのインストール

$ brew install sdl sdl_image sdl_ttf portmidi libogg libvorbis
$ brew install sdl_mixer

headonly リポジトリをhomebrewに追加

$ brew tap homebrew/headonly

取り込み元である、 https://github.com/Homebrew/homebrew-head-only と見てみると
こちらも homebrew-core に移行したらしいため、 deprecated となっている。コマンド自体は通ったが、不要かも?

SMPEGインストール

$ brew install smpeg 

Mercurialインストール

$ brew install mercurial 

pygameインストール

$ pip3 install hg+http://bitbucket.org/pygame/pygame

以下のようなエラーが発生。

Command "/usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/wb/3z64dtmx7gs3mk5l2g73h5040000gn/T/pip-req-build-ogixopgy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/wb/3z64dtmx7gs3mk5l2g73h5040000gn/T/pip-record-5a_4ya4b/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/wb/3z64dtmx7gs3mk5l2g73h5040000gn/T/pip-req-build-ogixopgy/

よくわからないので、 代わりに以下のコマンドでインストール。
(このコマンドでインストールするなら、Mercurialのインストール不要だったかもしれない。)

$ pip3 install pygame

6. 動作確認

ターミナルからpython3を起動。
import pygame と入力してエラーがでないことを確認。

$ python3
Python 3.7.0 (default, Sep  7 2018, 11:45:06) 
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
16
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15