Getting Python + OS X together
Since a week I’ve been looking for ways to create Mac apps using Python. Here are a few important tutorials/articles which got me my setup -
Many tutorials show up CocoaPython option in XCode’s ‘create new project’ wizard. It wasn’t there in XCode 3.2.3, so I made myself believe that I need to get something, and so began my exploration.
At first I decided that it would be cool to be able to write a pygame app and turn it into a portable binary -
- Thanks to kontinuity setting up PyObjC on Python 2.6.5 is a cakewalk
- Now you need pygame, which is another recipe in itself. Grab the pdf guide here. Clear instructions that work
- Py2App would fail looking for
Just copy the main-fat file in the same path as main-x86_64
- Test py2app over a small pygame example/script. Now the app would fail to load up. Have a look at the ‘Console’ -If using setuptools, just set the argv_emulation under OPTIONS as False to pass through.Also don’t forget to add ‘zlib’ to includes in case console shows errors related to a zlib import.
- Now you have your working pygame+py2app setup. Also if you’re looking for Physics engines, I would recommend you go for PyBox2D. Though PyBox2D’s documentation is sparse and examples lacking, it is something that works compatibly with py2app.
I also tried pymunk, though it builds up and works fine, but the py2app generated binary always dies out in a segmentation fault. Pretty unreliable for py2app as observed on OSX 10.6.4. Also you would have to put in libchipmunk.dylib manually into app archive after every build.
Now thats cool in case you’re an indie game-dev aligned python charmer with a mac.
For those of you looking for XCode+PyObjC development, the good news is that Python2.5 and PyObjC 2.0 have been bundled in your OS X installation ever since 10.5. All you need to do is to follow what Ioanna has to say about getting the XCode templates in. But remember this would use up python26-apple instead of your goody macports versions and would have its own set of issues along (as in with getting the 3rd party modules up and running)
I couldn’t get all of it working on XCode 3.2.3, OS X 10.6.4, if you too don’t see ‘Python’ under File Templates in XCode, when say you’re trying to add a class through the gui, just follow these -
Goto ~/Library/Application\ Support/Developer/Shared/Xcode/File\ Templates/ where you have copied the File Templates. Create a folder named Python here and move all the “Python NS…” folders inside it.