Difference between revisions of "Python"

From AwkwardTV
Jump to: navigation, search
(How to Install Python 2.5 on Apple TV: added space to fix typo)
m (How to Install Python 2.5 on Apple TV)
 
(13 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
==How to Install Python 2.5 on Apple TV==
 
==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 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
+
Download the Universal Python 2.5 (Mac OS X 10.3.9 and later, Intel or PPC) package to your mac, from:
  
http://www.pythonmac.org/packages/py25-fat/dmg/python-2.5-macosx.dmg
+
http://python.org/ftp/python/2.5.4/python-2.5.4-macosx.dmg
  
Copy the dmg to the Apple TV that already has ssh enabled. Use the -1 (one) argument to scp to use SSH version 1.
+
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):
  scp -1 http://www.pythonmac.org/packages/py25-fat/dmg/python-2.5-macosx.dmg frontrow@192.168.1.202: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 frontrow@appletv.local 
  
 
+
and change directory to where you plan to download the package:
  ssh -1 frontrow@192.168.1.202 
+
 
+
   cd ~/Documents
 
 
Change directory to Documents
 
 
 
 
 
   cd Documents
 
  
 +
cd means change directory, ~ means the root of the user folder.  Next, execute the wget (Web-Get) command to retrieve python:
 +
 +
  wget http://python.org/ftp/python/2.5.4/python-2.5.4-macosx.dmg
  
 
Make a directory into which we will extract the Python.framework package files from the installer dmg
 
Make a directory into which we will extract the Python.framework package files from the installer dmg
 
 
    
 
    
 
   mkdir Python.framework
 
   mkdir Python.framework
Mount the disk image
+
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-macosx.dmg   
+
   sudo hdiutil mount python-2.5.4-macosx.dmg   
  
 
We want to install just the Python.framework
 
We want to install just the Python.framework
Line 40: Line 35:
  
 
    
 
    
   cd /Volumes/Univeral\ MacPython\2.5/MacPython.mpkg/Contents/Packages/PythonFramework-2.5.pkg/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
+
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/
 
   cp -r * ~/Documents/Python.framework/
Unmount the .dmg disk image
 
  
 
+
Go to your local copy of Python.framework and 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
 
  
 
 
 
   cd ~/Documents/Python.framework/   
 
   cd ~/Documents/Python.framework/   
 +
  sudo hdiutil unmount /Volumes/Universal\ MacPython\ 2.5.4/
  
Unzip the entire gzipped archive
+
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
 
   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)
 
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   
 
   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.
 
Delete the .pax file now that we have extracted everything from it.
Line 103: Line 97:
  
  
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’
+
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!
 
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   
 
   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.)
make our new file executable
 
 
 
 
 
  chmod 755 postflight.root 
 
 
 
  
 
Now lets execute postflight.root and watch how quickly the AppleTV complies python source code.
 
Now lets execute postflight.root and watch how quickly the AppleTV complies python source code.
  
 
    
 
    
   sudo ./postflight.root
+
   sudo sh ./postflight.root

Latest revision as of 20:42, 26 February 2010

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:

http://python.org/ftp/python/2.5.4/python-2.5.4-macosx.dmg

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:

 wget http://python.org/ftp/python/2.5.4/python-2.5.4-macosx.dmg 

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


 <key>IFPkgFlagDefaultLocation</key>   
 <string>/Library/Frameworks/Python.framework</string>  

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