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!

7 comments:

  1. This is awesome!

    Is there a way to edit /etc/profile directly? Right now I'm using iFile to copy it into the Textastic directory, edit it, and then copy it back.

    ReplyDelete
  2. Wow thank you so freaking much thank you thank you thank you really.... I have been looking for this for days and days... I'm new to programming and have been directed to learn python first only problem was i don't spend time at home too much ... So being able to learn it on my iPad is exactly what I need it thank you again ... You have no idea how much you have helped ...

    ReplyDelete
  3. Hello!

    Great little guide, but there's a step some people might have problems with:

    In Cydia, the Python package will not appear unless you identify yourself as a developer. This is done in Sources -> Settings

    Thanks for your work!

    ReplyDelete
  4. didn't know you could program in an iPad :)
    BTW, I also have a blog and a web directory, would you like to exchange links? let me know on emily.kovacs14@gmail.com

    ReplyDelete
  5. How to change root and Mobile password, please help

    Thanks

    ReplyDelete
  6. Great tip, cheers.
    I can't however find the .bashrc
    It says the file can't be found.
    Any ideas?

    ReplyDelete
  7. odoo customizationERP for manufacturing, ecommerce and open source erp: are you looking for odoo implementation? Then choose us. We are experienced, powered by superior technical.

    ReplyDelete