/var/log

技術系のあれこれ。※内容は個人の発言であり、所属する組織を代表するものではありません。

pygame

[環境]
OS : Mac OS X Snow Leopard (10.6.4)
Python : Python 2.6.1


pygameをインストールしたいともって
サンプルソース的なものを実行したんですが...

background = pygame.image.load(background_image_filename).convert()

この部分で,

Traceback (most recent call last):
  File "helloworld.py", line 17, in <module>
    background = pygame.image.load(background_image_filename).convert()
pygame.error: File is not a Windows BMP file

というエラーに遭遇...



調べていくと,pygame を easy_install で入れたときに SDL ライブラリ群の存在を認識してくれてなかったようです...
(一度,前の記事の削除の手順で削除してから,インストールしなおしてわかりました)

以前に,finksdl 周りは全部インストールしてたんですが...
どうも,/System/Library/Framework に入ってないと意味がないようです.

ということで...
http://www.pygame.org/wiki/MacCompile
http://nbtklog.jp/2009-10-26/install-pygame191-for-mac-os-x-snow-leopard/
を参考にさせてもらって, /System/Library/Framework にひつよなモノを入れてみる.


そんで

$ sudo easy_install pygame

をすると...

$ sudo easy_install pygame
Searching for pygame
Reading http://pypi.python.org/simple/pygame/
Reading http://www.pygame.org/
Reading http://www.pygame.org/download.shtml
Best match: pygame 1.9.1release
Downloading http://www.pygame.org/ftp/pygame-1.9.1release.zip
Processing pygame-1.9.1release.zip
Running pygame-1.9.1release/setup.py -q bdist_egg --dist-dir /tmp/easy_install-oOvP7S/pygame-1.9.1release/egg-dist-tmp-qQ8Wbu


WARNING, No "Setup" File Exists, Running "config.py"
Using Darwin configuration...

Hunting dependencies...
Framework SDL found
Framework SDL_ttf found
Framework SDL_image found
Framework SDL_mixer found
Framework smpeg not found
PNG     : not found
JPEG    : not found
SCRAP   : not found
PORTMIDI: not found
Framework CoreMidi found

If you get compiler errors during install, doublecheck
the compiler flags in the "Setup" file.

となりました.
Framework系は見つかるようになったようなのですが...


個人的には,fink で入れた sdl のライブラリ群をどのようにしたら 使えるようになるのかが気になります...

Linuxだと ldconfig的なものを使えば良いのだろうけど,Macでは果たして?
今後の課題ですな...







因に,ここまでの作業だけでは実はうまくいきませんでしたorz

お察しの通り,PNGJPEGが見つかってませんorz
(finkでは入っているのにー)


所謂,libjpeg とか libpng とかが入ってないとダメなんですよー

http://www.pygame.org/docs/ref/image.html
によると...

The image module is a required dependency of Pygame, but it only optionally supports any extended file formats. By default it can only load uncompressed BMP images. When built with full image support, the pygame.image.load - load new image from a file function can support the following formats.

"When built with full image support" ということで,完全にライブラリがそろってないとダメなようです.




ということで

  • libjpeg

http://www.ijg.org/

  • libpng

http://www.libpng.org/pub/png/libpng.html

をそれぞれ通常通り
ダウンロードして解凍したフォルダに入って

$ ./configure
$ make
$ sudo make install

してやると,/usr/local/lib に必要なライブラリが入ります.


この状態でもう一回,pygame を削除した後に

$ sudo easy_install pygame

してやれば,

Using Darwin configuration...

Hunting dependencies...
Framework SDL found
Framework SDL_ttf found
Framework SDL_image found
Framework SDL_mixer found
Framework smpeg not found
PNG     : found
JPEG    : found
SCRAP   : not found
PORTMIDI: not found
Framework CoreMidi found

ってな感じになってインストールも無事に終了します.





長々となりましたが,一度入れてしまえばあとは楽...だと思うので頑張りましょう.

(これで,py2app出来なかったら泣けますがw)