Tags

, , ,

Share it

The goal for today was to talk to a RESTful bottle.py web service from an iOS app on my phone that is built using the kivy library.

As always, goals should be broken down into smaller more manageable steps:

1. Make a web service using bottle.py.
2. Install kivy.
3. Take a Hello World kivy example and put a button on there that calls the web service from step 1.
4. Deploy.

Easy peasy!

Well slow down the pony train. The rest of the day, as I would find out, would be broken down in increasingly smaller steps, down to manually patching the source of a kivy dependency. YUK!
Now, 5 hours in and I finally have kivy working on Mountain Lion. Not sure which is the beast, kivy or ML.

Here are my basic steps just to get kivy working on Mountain Lion:

First off, I definitely want to use virtualenv to prevent jeopardizing any other project. Let’s say I have prior experience. I strongly recommend to anyone working with Python to learn all about virtualenv. Once you have it installed it’s only three commands to learn (mkvirtualenv, workon, deactivate).

mkvirtualenv kivy
workon kivy
cd kivy

Pygame is dependent on X11, which no longer comes built-in with Mountain Lion.
Instead, install Quartz. I just installed the binary; this is not something that will be deployed.

Next install Cython.
Although 0.16 is the latest version, kivy users who deploy to iOS report success with the 0.15 version. I’m not going to be the test subject for 0.16 today.

I downloaded Cython 0.15 and untarred it in a directory named cython. Installed it like so:

cd cython
python setup.py install

The next dependency is pygame. At least, this will be very useful during the development stage in order to support showing a window.

Unfortunately, the most current pygame doesn’t compile on Mountain Lion. Fortunately someone who knows more than me came up the the solution.

With that out of the way pygame can be successfully installed from source. I learned how you can use pip to install from a local directory. It’s trivial:

hg clone http://bitbucket.org/pygame/pygame
pip install ./pygame

Now install kivy from source:

cd kivy
python setup.py install

My hello world kivy program can be started:

python main.py

Bingo!

I have omitted quite a lot of trials and errors in order to provide for maximum readingwriting pleasure.