| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1 | ============ |
| 2 | MacOSX Notes |
| 3 | ============ |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 4 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 5 | This document provides a quick overview of some Mac OS X specific features in |
| 6 | the Python distribution. |
| 7 | |
| 8 | |
| 9 | Building and using a universal binary of Python on Mac OS X |
| 10 | =========================================================== |
| 11 | |
| 12 | 1. What is a universal binary |
| 13 | ----------------------------- |
| 14 | |
| 15 | A universal binary build of Python contains object code for both PPC and i386 |
| 16 | and can therefore run at native speed on both classic powerpc based macs and |
| 17 | the newer intel based macs. |
| 18 | |
| 19 | 2. How do I build a universal binary |
| 20 | ------------------------------------ |
| 21 | |
| 22 | You can enable universal binaries by specifying the "--enable-universalsdk" |
| 23 | flag to configure:: |
| 24 | |
| 25 | $ ./configure --enable-universalsdk |
| 26 | $ make |
| 27 | $ make install |
| 28 | |
| 29 | This flag can be used a framework build of python, but also with a classic |
| 30 | unix build. Either way you will have to build python on Mac OS X 10.4 (or later) |
| 31 | with Xcode 2.1 (or later). You also have to install the 10.4u SDK when |
| 32 | installing Xcode. |
| 33 | |
| 34 | |
| 35 | Building and using a framework-based Python on Mac OS X. |
| 36 | ======================================================== |
| 37 | |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 38 | |
| Brett Cannon | 98809b7 | 2004-12-06 06:01:13 +0000 | [diff] [blame] | 39 | 1. Why would I want a framework Python instead of a normal static Python? |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 40 | -------------------------------------------------------------------------- |
| 41 | |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 42 | The main reason is because you want to create GUI programs in Python. With the |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 43 | exception of X11/XDarwin-based GUI toolkits all GUI programs need to be run |
| 44 | from a fullblown MacOSX application (a ".app" bundle). |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 45 | |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 46 | While it is technically possible to create a .app without using frameworks you |
| 47 | will have to do the work yourself if you really want this. |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 48 | |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 49 | A second reason for using frameworks is that they put Python-related items in |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 50 | only two places: "/Library/Framework/Python.framework" and |
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame^] | 51 | "/Applications/MacPython <VERSION>" where ``<VERSION>`` can be e.g. "2.6", |
| 52 | "3.1", etc.. This simplifies matters for users installing |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 53 | Python from a binary distribution if they want to get rid of it again. Moreover, |
| 54 | due to the way frameworks work a user without admin privileges can install a |
| 55 | binary distribution in his or her home directory without recompilation. |
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 56 | |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 57 | 2. How does a framework Python differ from a normal static Python? |
| 58 | ------------------------------------------------------------------ |
| 59 | |
| 60 | In everyday use there is no difference, except that things are stored in |
| 61 | a different place. If you look in /Library/Frameworks/Python.framework |
| 62 | you will see lots of relative symlinks, see the Apple documentation for |
| 63 | details. If you are used to a normal unix Python file layout go down to |
| 64 | Versions/Current and you will see the familiar bin and lib directories. |
| 65 | |
| 66 | 3. Do I need extra packages? |
| 67 | ---------------------------- |
| 68 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 69 | Yes, probably. If you want Tkinter support you need to get the OSX AquaTk |
| 70 | distribution, this is installed by default on Mac OS X 10.4 or later. If |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 71 | you want wxPython you need to get that. If you want Cocoa you need to get |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 72 | PyObjC. |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 73 | |
| 74 | 4. How do I build a framework Python? |
| 75 | ------------------------------------- |
| 76 | |
| Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 77 | This directory contains a Makefile that will create a couple of python-related |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 78 | applications (fullblown OSX .app applications, that is) in |
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame^] | 79 | "/Applications/MacPython <VERSION>", and a hidden helper application Python.app |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 80 | inside the Python.framework, and unix tools "python" and "pythonw" into |
| 81 | /usr/local/bin. In addition it has a target "installmacsubtree" that installs |
| 82 | the relevant portions of the Mac subtree into the Python.framework. |
| Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 83 | |
| Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 84 | It is normally invoked indirectly through the main Makefile, as the last step |
| 85 | in the sequence |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 86 | |
| 87 | 1. ./configure --enable-framework |
| 88 | |
| 89 | 2. make |
| 90 | |
| 91 | 3. make install |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 92 | |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 93 | This sequence will put the framework in /Library/Framework/Python.framework, |
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame^] | 94 | the applications in "/Applications/MacPython <VERSION>" and the unix tools in |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 95 | /usr/local/bin. |
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 96 | |
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 97 | Installing in another place, for instance $HOME/Library/Frameworks if you have |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 98 | no admin privileges on your machine, has only been tested very lightly. This |
| 99 | can be done by configuring with --enable-framework=$HOME/Library/Frameworks. |
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame^] | 100 | The other two directories, "/Applications/MacPython-<VERSION>" and |
| 101 | /usr/local/bin, will then also be deposited in $HOME. This is sub-optimal for |
| 102 | the unix tools, which you would want in $HOME/bin, but there is no easy way to |
| 103 | fix this right now. |
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 104 | |
| 105 | If you want to install some part, but not all, read the main Makefile. The |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 106 | frameworkinstall is composed of a couple of sub-targets that install the |
| 107 | framework itself, the Mac subtree, the applications and the unix tools. |
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 108 | |
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 109 | There is an extra target frameworkinstallextras that is not part of the |
| 110 | normal frameworkinstall which installs the Demo and Tools directories |
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame^] | 111 | into "/Applications/MacPython <VERSION>", this is useful for binary |
| 112 | distributions. |
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 113 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 114 | What do all these programs do? |
| 115 | =============================== |
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 116 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 117 | "IDLE.app" is an integrated development environment for Python: editor, |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 118 | debugger, etc. |
| 119 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 120 | "PythonLauncher.app" is a helper application that will handle things when you |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 121 | double-click a .py, .pyc or .pyw file. For the first two it creates a Terminal |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 122 | window and runs the scripts with the normal command-line Python. For the |
| 123 | latter it runs the script in the Python.app interpreter so the script can do |
| 124 | GUI-things. Keep the "alt" key depressed while dragging or double-clicking a |
| 125 | script to set runtime options. These options can be set once and for all |
| 126 | through PythonLauncher's preferences dialog. |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 127 | |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 128 | The commandline scripts /usr/local/bin/python and pythonw can be used to run |
| 129 | non-GUI and GUI python scripts from the command line, respectively. |
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 130 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 131 | How do I create a binary distribution? |
| 132 | ====================================== |
| Jack Jansen | 8ba4220 | 2002-09-06 20:24:51 +0000 | [diff] [blame] | 133 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 134 | Go to the directory "Mac/OSX/BuildScript". There you'll find a script |
| 135 | "build-installer.py" that does all the work. This will download and build |
| 136 | a number of 3th-party libaries, configures and builds a framework Python, |
| 137 | installs it, creates the installer pacakge files and then packs this in a |
| 138 | DMG image. |
| Jack Jansen | 4f90137 | 2004-07-15 21:30:41 +0000 | [diff] [blame] | 139 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 140 | The script will build a universal binary, you'll therefore have to run this |
| 141 | script on Mac OS X 10.4 or later and with Xcode 2.1 or later installed. |
| Jack Jansen | 8ba4220 | 2002-09-06 20:24:51 +0000 | [diff] [blame] | 142 | |
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 143 | All of this is normally done completely isolated in /tmp/_py, so it does not |
| 144 | use your normal build directory nor does it install into /. |
| Jack Jansen | 8ba4220 | 2002-09-06 20:24:51 +0000 | [diff] [blame] | 145 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 146 | Because of the way the script locates the files it needs you have to run it |
| 147 | from within the BuildScript directory. The script accepts a number of |
| 148 | command-line arguments, run it with --help for more information. |
| Jack Jansen | 8ba4220 | 2002-09-06 20:24:51 +0000 | [diff] [blame] | 149 | |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 150 | Odds and ends |
| 151 | ============= |
| Jack Jansen | 408c16f | 2001-09-11 11:30:02 +0000 | [diff] [blame] | 152 | |
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 153 | Something to take note of is that the ".rsrc" files in the distribution are |
| 154 | not actually resource files, they're AppleSingle encoded resource files. The |
| 155 | macresource module and the Mac/OSX/Makefile cater for this, and create |
| 156 | ".rsrc.df.rsrc" files on the fly that are normal datafork-based resource |
| 157 | files. |
| Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 158 | |
| Brett Cannon | 98809b7 | 2004-12-06 06:01:13 +0000 | [diff] [blame] | 159 | Jack Jansen, Jack.Jansen@cwi.nl, 15-Jul-2004. |
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 160 | Ronald Oussoren, RonaldOussoren@mac.com, 26-May-2006 |