LoginSignup
16
17

More than 5 years have passed since last update.

Kivy + Python3 on OSX 環境整備

Last updated at Posted at 2015-06-20

PythonでiOS/Androidアプリが書けると知り、早速環境整備しようとするも、以外と手間取ったのでメモ。公式ドキュメントはこちら

必要なパッケージインストール

各種ライブラリ

Kivyがpygameに依存しており、さらにそのpygameが依存しているSDLライブラリ群を事前にインストールする必要があり、さらにsdl_ttfが依存しているfreetypeをインストールする際に起きるエラーを回避するため、libpngを--universal付きでインストールする必要がある。ややこしい…。

brew reinstall libpng --universal
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi

ソースからインストール

普通にリポジトリをcloneしてからインストールする方法

ソースをゲットする。

git clone --depth 1 -b 1.9.0 --single-branch  https://github.com/kivy/kivy.git
git clone --depth 1 -b 0.21.2 --single-branch https://github.com/cython/cython.git

まずはCythonをビルドしてインストールする。

cd cython
python3 ./setup.py build
sudo python3 setup.py install

同様にKivyもビルドしてインストールする。

python3 setup.py build_ext --inplace -f
sudo python3 setup.py install

インストールできていることを確認。

pip3 list | grep -e Cython -e Kivy
Cython (0.21.2)
Kivy (1.9.0)

pipにリポジトリを直接指定する方法

下記のようにすれば、いちいちgit cloneせず、直接リポジトリを指定してインストールできる。

sudo pip3 install git+https://github.com/kivy/kivy.git@1.9.0
sudo pip3 install git+https://github.com/cython/cython.git@0.21.2

サンプルコード実行

Kivy公式サイトのサンプルコードを実行してみると、OSXのUIが表示された。これでやっとスタートラインに立つことができた。

#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from kivy.app import App
from kivy.uix.widget import Widget

class PongGame(Widget):
    pass

class PongApp(App):
    def build(self):
        return PongGame()

if __name__ == "__main__":
    PongApp().run()

スクリーンショット 2015-06-20 21.43.04.png

参考資料

16
17
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
17