Python on the PS3

Please note that the content on this page is gradually being moved to its new home at http://python-ps3.sourceforge.net/

As you may know, I've been writing my PS3 stuff with a view to building up a library suitable for writing games and as I thought about it more the idea of using a scripting language for the game seemed the most logical way forward. I plumped on python as I'd used it before for a couple of small jobs and it seemed like a nice language with a lot of support. Plus, it has the advantage of being pre-installed on most Linux distributions and very easy to extend, and so the PS3 library for python was born...

Brief bullet points of the current build:

After about a day and a half development, the core of the library was in place but in a not very visible way. It seemed that the only way I could actually demonstrate this to all be good stuff is by writing a quick game. And breakout is one of the simplest, so I spent another day writing that. It's important to have a good demo on release... So, I'll settle for this half-hearted attempt at a breakout game whose main redeeming feature is that it has alpha transparency on all the blocks!

Just to whet your interest, here's an example of how easy the code can be (taken directly from the test.py file):

image = Blittable(Image.open("miglu.jpg"))
for count in xrange(screen.height-image.height):
        screen.clear()
        screen.blit(image, (count,count) )
        screen.flip()
        screen.wait()

Download

The latest release 0.1.2 adds support for SPU blitting; please visit the sourceforge page to download.

SourceForge.net Logo I've now moved development to sourceforge, so the latest files can be found here. This document has not been updated to reflect the fact that the installation instructions are now slightly different.

Building and running it

The python side of things is very easy as it's all standardised and I've included a precompiled SPU image in the distribution which just gets linked in (although you will still need libspe). Alternatively, you can use "make" and build the whole lot from scratch.

But, I'm getting ahead of myself. Firstly, you'll need python installed on your box. I guess if you don't already have it, you'll have to follow whatever instructions your distribution gives you. Also please make sure you have libjpeg62 and libfreetype2 installed.

Next, you'll absolutely need the Python Image Library in order to load images. With ubuntu, just apt-get install python-imaging or if you prefer to build from source or are using another distro:

$ wget http://effbot.org/downloads/Imaging-1.1.6.tar.gz
$ tar xvfz Imaging-1.1.6.tar.gz
$ cd Imaging-1.1.6
$ python setup.py install

and then installing my extension is fairly similar:

$ wget http://www.ranulf.net/ps3/PS3-0.1.3c.tar.gz
$ tar xvfz PS3-0.1.3c.tar.gz
$ cd PS3-0.1.3c
$ python setup.py install
$ ./test.py

If all that worked, you should be ready to go. There's a simple breakout game in that directory, launch it by typing ./breakout.py.

Things for the future

Finally...

Some of you might be wondering why I ignored Lua. Actually I didn't. I took a brief look on lua.org and luaplayer.org and then e-mailed one of the luaplayer developers to find out what needed to be done to port it. Well, I didn't hear anything until today (and I actually started development at the start of the long weeked) but in the mean time, I'd taken a closer look at lua and realised that I really disliked the language. Lots of things looked really, really ugly and that's when I remembered using python some years ago and really liking it. I was going to have to learn lua internals anyway, so not knowing how to write python extensions wasn't an issue and in actual fact, python extension turn out to be very easy after all. There's also a wealth of other libraries available for other tasks too. So, apologies to the guy I e-mailed for wasting his time, and if you're reading this then I hope it doesn't come as too much of a surprise than I went a different route!