Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame^] | 1 | Building and using a framework-based Python on Mac OS X. |
| 2 | -------------------------------------------------------- |
| 3 | |
| 4 | This document provides a quick introduction to framework-based Python. |
| 5 | It is rather terse and probably incomplete, please send me feedback. |
| 6 | |
| 7 | 1. Why would I want a framework Python in stead of a normal static Python? |
| 8 | -------------------------------------------------------------------------- |
| 9 | |
| 10 | The main reason is because you want to create GUI programs in Python. With |
| 11 | the exception of X11/XDarwin-based GUI toolkits it appears that all GUI programs |
| 12 | need to be run from a fullblown MacOSX application (a ".app" bundle). |
| 13 | |
| 14 | While it is technically possible to create a .app without using frameworks |
| 15 | you will have to do the work yourself if you really want this. |
| 16 | |
| 17 | A second reason for using frameworks is that they put Python-related items |
| 18 | in only two places: /Library/Framework/Python.framework and /Applications/Python. |
| 19 | This simplifies matters for users installing Python from a binary distribution |
| 20 | if they want to get rid of it again. Moreover, due to the way frameworks |
| 21 | work a user without admin privileges can install a binary distribution in |
| 22 | his or her home directory without recompilation. |
| 23 | |
| 24 | 2. How does a framework Python differ from a normal static Python? |
| 25 | ------------------------------------------------------------------ |
| 26 | |
| 27 | In everyday use there is no difference, except that things are stored in |
| 28 | a different place. If you look in /Library/Frameworks/Python.framework |
| 29 | you will see lots of relative symlinks, see the Apple documentation for |
| 30 | details. If you are used to a normal unix Python file layout go down to |
| 31 | Versions/Current and you will see the familiar bin and lib directories. |
| 32 | |
| 33 | 3. Do I need extra packages? |
| 34 | ---------------------------- |
| 35 | |
| 36 | Yes, probably. If you want to be able to use the PythonIDE you will need to |
| 37 | get Waste, an all-singing-all-dancing TextEdit replacement, from www.merzwaren.com. |
| 38 | It will unpack into a folder named something like "Waste 2.1 Distribution". Make |
| 39 | a symlink called "waste" to this folder, somewhere beside your Python source |
| 40 | distribution (it can be "../waste", "../../waste", etc). |
| 41 | |
| 42 | If you want Tkinter support you need to get the OSX AquaTk distribution. If you |
| 43 | want wxPython you need to get that. If you want Cocoa you need to get pyobjc. |
| 44 | Because all these are currently in a state of flux please refer to |
| 45 | http://www.cwi.nl/~jack/macpython.html, which should contain pointers to more |
| 46 | information. |
| 47 | |
| 48 | 4. How do I build a framework Python? |
| 49 | ------------------------------------- |
| 50 | |
Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 51 | This directory contains a Makefile that will create a couple of python-related |
| 52 | applications (fullblown OSX .app applications, that is) in /Applications/Python, |
| 53 | and a hidden helper application Python.app inside the Python.framework. In addition |
| 54 | it has a target "installmacsubtree" that installs the relevant portions of the |
| 55 | Mac subtree into the Python.framework. |
Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 56 | |
Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 57 | It is normally invoked indirectly through the main Makefile, as the last step |
| 58 | in the sequence |
| 59 | 1. configure --enable-framework |
| 60 | 2. make |
| 61 | 3. make frameworkinstall |
| 62 | 4. make osxapps |
Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame^] | 63 | 5. [optional] in Mac/OSX do "make installunixprograms", see below. |
| 64 | |
| 65 | This sequence will put the framework in /Library/Framework/Python.framework and |
| 66 | the applications in /Applications/Python. Building in another place, for instance |
| 67 | $HOME/Library/Frameworks if you have no admin privileges on your machine, has only |
| 68 | been tested very lightly. |
| 69 | |
| 70 | 5. What do all these programs do? |
| 71 | --------------------------------- |
| 72 | |
| 73 | PythonIDE.app is an integrated development environment for Python: editor, |
| 74 | debugger, etc. |
| 75 | |
| 76 | PythonLauncher.app is a helper application that will handle things when you |
| 77 | double-click a .py, .pyc or .pyw file. For the first two it creates a Terminal |
| 78 | window and runs the scripts with the normal command-line Python. For the latter |
| 79 | it runs the script in the Python.app interpreter so the script can do GUI-things. |
| 80 | Keep the "alt" key depressed while dragging or double-clicking a script to set |
| 81 | runtime options. These options can be set once and for all through PythonLauncher's |
| 82 | preferences dialog. |
| 83 | |
| 84 | BuildApplet.app creates an applet from a Python script. Drop the script on it |
| 85 | and out comes a full-featured MacOS application. There is much more to this, to |
| 86 | be supplied later. Some useful (but outdated) info can be found in Mac/Demo. |
| 87 | |
| 88 | If you install the commandline scripts /usr/local/bin/python and pythonw these |
| 89 | can be used to run non-GUI and GUI python scripts from the command line, respectively. |
| 90 | |
| 91 | 6. Odds and ends. |
| 92 | ----------------- |
Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 93 | |
Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 94 | The interesting targets in the makefile are: |
| 95 | installmacsubtree - explained above, |
| 96 | dontinstallmacsubtree - Put only a .pth file into the framework (pointing to this |
| 97 | sourcetree), which may be easier for development, |
| 98 | install_all - install all three .app applications, |
| 99 | install_Python - install the hidden interpreter .app into the framework, |
| 100 | install_PythonLauncher - install the user-visible script launch helper |
| 101 | install_IDE - install the IDE |
| 102 | installunixprograms - install symlinks/scripts mimicking normal unix Python into |
| 103 | /usr/local. |
Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame^] | 104 | |
| 105 | The PythonLauncher is actually an Objective C Cocoa app built with Project Builder. |
| 106 | It could be a Python program, except for the fact that pyobjc is not a part of |
| 107 | the core distribution, and is not completely finished yet as of this writing. |
Jack Jansen | 408c16f | 2001-09-11 11:30:02 +0000 | [diff] [blame] | 108 | |
Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 109 | Something to take note of is that the ".rsrc" files in the distribution are not |
Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame^] | 110 | actually resource files, they're AppleSingle encoded resource files. The macresource |
| 111 | module and the Mac/OSX/Makefile cater for this, and create ".rsrc.df.rsrc" files |
| 112 | on the fly that are normal datafork-based resource files. |
Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 113 | |
Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 114 | Jack Jansen, jack@oratrix.com, 02-Aug-02 |