How to Install Python 2.5 on Apple TV
Source: Michael Hanney http://michaelhanney.com/blog/2008/03/27/how-to-install-python-on-apple-tv/
You will need to Mount ReadWrite the system disk /dev/disk0s4 to make this work and also requires that you have gunzip on your TV
Download the Universal Python 2.5 (Mac OS X 10.3.9 and later, Intel or PPC) package
Copy the dmg to the Apple TV that already has ssh enabled. Use the -1 (one) argument to scp to use SSH version 1.
scp -1 http://www.pythonmac.org/packages/py25-fat/dmg/python-2.5-macosx.dmg firstname.lastname@example.org:Documents/python-2.5-macosx.dmg
Log in to the Apple TV over SSH, also uses the -1 argument to use SSH version 1. (The IP address of my Apple TV is 192.168.1.202, obviously your may be different).
ssh -1 email@example.com
Change directory to Documents
Make a directory into which we will extract the Python.framework package files from the installer dmg
Mount the disk image
sudo hdiutil mount python-2.5-macosx.dmg
We want to install just the Python.framework
“This package installs Python.framework, that is the python interpreter and the standard library. This also includes Python wrappers for lots of Mac OS X API’s.”
Change directory to the mount location and take a look around at the contents
cd /Volumes/Univeral\ MacPython\ 2.5/MacPython.mpkg/Contents/Packages/PythonFramework-2.5.pkg/Contents
Copy all of the Contents directory to our ~/Documents/Python.framework directory
cp -r * ~/Documents/Python.framework/
Unmount the .dmg disk image
sudo hdiutil unmount /Volumes/Univeral\ MacPython\ 2.5
Prepare to manually move (or copy) the contents of the installer to the default locations on the Apple TV
Unzip the entire gzipped archive
Extract the contents of the pax archive. (I am not familiar with pax yet, but I guess it is like a tar)
pax -r -f Archive.pax
Delete the .pax file now that we have extracted everything from it.
rm -rf Archive.pax
So where do we install the archive contents? We see from the Info.plist that the default installation destination is /Library/Frameworks/Python.framework
Let’s manually create that directory and start moving files
mkdir /Library/Frameworks/Python.framework mv Versions /Library/Frameworks/Python.framework
Let’s recreate those symbolic links in the installation directory
cd /Library/Frameworks/Python.framework ln -s Versions/Current/Headers Headers ln -s Versions/Current/Python Python ln -s Versions/Current/Resources Resources
The python runtime executable is at /Library/Frameworks/Python.framework/Versions/Current/bin/python. We want to leave it there. All we need to do now is create the symbolic link in /usr/bin
sudo ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python /usr/bin/python
Testing it out
We haven’t visited the Resources directory yet. I’m not entirely sure how the OS X installer would have used this, if at all, but there is a shell script called postflight in /Resources/ that recompiles the .py files library we just installed. It looks important so I’m going to execute it. First I’m going to change to that directory.
Before we run the postflight shell script, we’ll edit the lines that change the ownership of the installation to admin, to root:admin because there is no admin user on the Apple TV. Instead, we will chown the installation to ‘root:admin’
At this point I remember I have not yet found a text editor on the Apple TV. No problem, we can use sed, the stream editor to replace ‘admin’ to ‘root:admin’ and save the result to a new file called postflight.root. Isn’t it great that Apple TV is a unix system!
cd ~/Documents/Python.framework/Resources sed s/admin/root:admin/ < postflight > postflight.root
Now lets execute postflight.root and watch how quickly the AppleTV complies python source code.
sudo sh ./postflight.root