Sunday, April 24, 2011

Python Development on an iPad

If you wish you could do some Python development on your iPad, this howto is for you.

Setup

Either you could get PyPad which is a very simplistic Python runtime environment (as of today, version 2.7.1 there is not even a way to save/import/export your code) or you could go for the full-blown thing:

  1. Jailbreak your iPad. I did it with this tutorial.
  2. From the Cydia app (which will get installed once you jailbreak your iPad), install the Python package.
  3. Either get MobileTerminal or iSSH to be able to open a console. If you choose iSSH, make sure to get OpenSSH from Cydia, too.
  4. Change your root and mobile (which is the default user) password to something else than the default "alpine".
  5. Get Textastic. This is the best Python-capable text editor I've found so far. Let me know if you know a better one.

Workflow

This is the workflow I'd recommend:
  1. You edit your .py files in Textastic. No need to save, it gets auto-saved every 10 seconds.
  2. Change to iSSH or MobileTerminal, go to the directory where Textastic saved your .py and run it with
    python yourcode.py
Et voila! If you're asking yourself where Textastic saves its files: in my case it was all in
/private/var/mobile/Applications/CA9452ED-D107-4D79-B774-1DFEF7097573/Documents
If you can't find your files, just do a
find / -name filename.py
to find the correct directory.

Alias

To make things easier, you could set up a neat little alias, that'll make it easier to change to your Textastic document directory:
  1. Add this line to your /var/root/.bashrc
    alias textastic="cd /private/var/mobile/Applications/CA9452ED-D107-4D79-B774-1DFEF7097573/Documents"
  2. Add this line to /etc/profile
    source /var/root/.bashrc
So whenever you type "textastic" into your terminal, it'll jump to the documents directory.

Keyboard


Typing code on the iPad is no joy with the screen keyboard. Get yourself a bluetooth keyboard like this, it helps tremendously.



Hope this help you all get started, be sure to leave some feedback, I'd appreciate it. Thanks!