From AwkwardTV
Jump to: navigation, search

How to Install Python 2.5 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 which can be found here Apple TV Binaries

Download the Universal Python 2.5 (Mac OS X 10.3.9 and later, Intel or PPC) package to your mac, from:

To do this, your Apple TV needs to have an SSH daemon installed and enabled. The easiest way to get the disk image onto your Apple TV is via the UNIX command wget.

Open Terminal from you Applications/Utilities folder and log in to the Apple TV over SSH; SSH may need the -1 argument to use SSH version 1. (appletv.local works for my Apple TV, you may need use the actual IP address instead or if connecting from a PC):

 ssh -1 frontrow@appletv.local  

and change directory to where you plan to download the package:

 cd ~/Documents

cd means change directory, ~ means the root of the user folder. Next, execute the wget (Web-Get) command to retrieve python:


Make a directory into which we will extract the Python.framework package files from the installer dmg

 mkdir Python.framework

Mount the disk image using the application hdiutil. You (seem to) need to run this with elevated permissions. Prefixing with "sudo" runs commands with elevated permissions, you will be prompted for a password, use "frontrow".

 sudo hdiutil mount python-2.5.4-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/Universal\ MacPython\ 2.5.4/MacPython.mpkg/Contents/Packages/PythonFramework-2.5.pkg/Contents  

Copy all of the Contents directory to our ~/Documents/Python.framework directory. Using -r copies recursively, i.e. it will copy the entire directory and subdirectories.

 cp -r * ~/Documents/Python.framework/

Go to your local copy of Python.framework and unmount the .dmg disk image

 cd ~/Documents/Python.framework/  
 sudo hdiutil unmount /Volumes/Universal\ MacPython\ 2.5.4/

Prepare to manually move (or copy) the contents of the installer to the default locations on the Apple TV; unzip the entire gzipped archive

 gunzip Archive.pax.gz

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  

(possible error: "pax: Unable to remove directory ./Resources <Directory not empty>" can be ignored)

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.

 cd /Library/Frameworks/Python.framework/Versions/Current/Resources  

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" (change owner) 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  

(AppleTV running 3.0.2 appears to have the nano text editor installed in /usr/bin/nano.)

Now lets execute postflight.root and watch how quickly the AppleTV complies python source code.

 sudo sh ./postflight.root