Python Nutter Posts: n/a
#1: Nov 4 '08
Mini install guide for python on the iPhone:
Cydia =Install SSH helps make initial configuration easier until you
get used to MobileTerminal
Cydia =Install MobileTerminal (closest to a bash shell you get on
your iPhone currently)
Cydia =Install Finder (graphical alternative to using
SSH/MobileTerminal for setting permissions, navigating file system,
moving/copying files, etc.)
Cydia =Install Python (currently installs CPython 2.5.1)
Cydia =Install PyObjC (this is your hook into iPhone API)
Cydia =Install Setuptools (currently install 0.6c7)
Cydia =Install iPhone/Python (examples, the hello world is a PyObjC
call into the iPhone API to load and scroll the contacts list in the
phone)
Not much left to have a fast running python implementation in your
pocket except IMHO ipython. Now that you have Setuptools installed,
you can run easy_install directly on your iPhone and download iPython
over the air.
The iPhone OS X architecture is of course a BSD Unix Userland
environment so you should feel right at home.
The two accounts, root and mobile both share the same default password
'alpine'. So once you setup your phone I recommend you change the
password for each account right away just to secure your phone a
little more. Root you won't need, Mobile is what the default account
is on the current iPhone OS implementation for the standard user
(you).
Easiest way to access your phone is SSH from your Mac, Linux, or
Windows box. (or just use MobileTerminal.app on the iphone directly
keeping in mind you will default to the mobile account in the shell)
Simply join your iPhone over wifi to your wireless access point or
ad-hoc-network, and display your iPhone's ip address. Now you are
ready to ssh into it.
$ssh root@
password: alpine
$chpass
while you are here might as well install ipython
$easy_install ipython
$exit
now same for mobile
$ssh root@
password: alpine
$chpass
$ipython
$cd .ipython
$nano ipy_user_conf.py
CTRL+W (find)
Where: #import ipy_editors
Single Tap screen to bring up a quick tap box grid of common unix
commands that get pasted when selected into the shell
Double Tap screen to hide the onscreen keyboard and see the full screen.
Drag Top left downward diagonally to right for CTRL
Drag Top right downward diagonally to left for TAB -- good for tab
completion in the bash shell
Delete the # comment character
Scroll down
Add your new line below the text "# Or roll your own"
ipy_editors.install_editors("nano +$line $file")
CTRL+X (exit)
Y to save
Now test your ipython link to nano editor
$ipython
In [1]: edit test.py
code>
In [2]: exit()
$cat test.py
$rm test.py
Its up to you where you want to save your python scripts. I would
suggest in Documents under your account (mobile).
$cd ~
$cd D*
$mkdir python
What is missing? Tkinter, iPhone uses its own API, Desktop Manager
(Springboard), etc.
What is different? PyObjC, this is where you get to use those iPhone
API calls from within your python script on the iPhone including GUI
API calls.
Now you have Python in your Pocket that you can take anywhere and whip
it out anytime the Python bug hits you and you want to work on some
code.
You can use SSH to move/copy/sync your files to your desktop.
Or other ways: AirSharing app over wifi, etc.
I'll be giving iPhone Python 2.5.1 a workout on on of Mark Lutz's
books and report any more gotchas that I come across.
Cheers,
PN