| 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 |  | 
| Ronald Oussoren | 86b33c8 | 2010-04-30 11:41:56 +0000 | [diff] [blame] | 8 | * ``--enable-framework[=DIR]`` | 
| Ronald Oussoren | 6f6c562 | 2009-12-24 14:03:19 +0000 | [diff] [blame] | 9 |  | 
|  | 10 | If this argument is specified the build will create a Python.framework rather | 
|  | 11 | than a traditional Unix install. See the section | 
|  | 12 | _`Building and using a framework-based Python on Mac OS X` for more | 
|  | 13 | information on frameworks. | 
|  | 14 |  | 
| Ronald Oussoren | 86b33c8 | 2010-04-30 11:41:56 +0000 | [diff] [blame] | 15 | If the optional directory argument is specified the framework it installed | 
|  | 16 | into that directory. This can be used to install a python framework into | 
|  | 17 | your home directory:: | 
|  | 18 |  | 
|  | 19 | $ configure --enable-framework=/Users/ronald/Library/Frameworks | 
|  | 20 | $ make && make install | 
|  | 21 |  | 
|  | 22 | This will install the framework itself in ``/Users/ronald/Library/Frameworks``, | 
|  | 23 | the applications in a subdirectory of ``/Users/ronald/Applications`` and the | 
|  | 24 | command-line tools in ``/Users/ronald/bin``. | 
|  | 25 |  | 
| Ronald Oussoren | 6f6c562 | 2009-12-24 14:03:19 +0000 | [diff] [blame] | 26 | * ``--with-framework-name=NAME`` | 
|  | 27 |  | 
|  | 28 | Specify the name for the python framework, defaults to ``Python``. This option | 
|  | 29 | is only valid when ``--enable-framework`` is specified. | 
|  | 30 |  | 
|  | 31 | * ``--enable-universalsdk[=PATH]`` | 
|  | 32 |  | 
|  | 33 | Create a universal binary build of of Python. This can be used with both | 
|  | 34 | regular and framework builds. | 
|  | 35 |  | 
|  | 36 | The optional argument specifies which OSX SDK should be used to perform the | 
|  | 37 | build. This defaults to ``/Developer/SDKs/MacOSX.10.4u.sdk``, specify | 
|  | 38 | ``/`` when building on a 10.5 system, especially when building 64-bit code. | 
|  | 39 |  | 
|  | 40 | See the section _`Building and using a universal binary of Python on Mac OS X` | 
|  | 41 | for more information. | 
|  | 42 |  | 
|  | 43 | * ``--with-univeral-archs=VALUE`` | 
|  | 44 |  | 
|  | 45 | Specify the kind of universal binary that should be created. This option is | 
|  | 46 | only valid when ``--enable-universalsdk`` is specified. | 
|  | 47 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 48 |  | 
|  | 49 | Building and using a universal binary of Python on Mac OS X | 
|  | 50 | =========================================================== | 
|  | 51 |  | 
|  | 52 | 1. What is a universal binary | 
|  | 53 | ----------------------------- | 
|  | 54 |  | 
|  | 55 | A universal binary build of Python contains object code for both PPC and i386 | 
|  | 56 | and can therefore run at native speed on both classic powerpc based macs and | 
|  | 57 | the newer intel based macs. | 
|  | 58 |  | 
|  | 59 | 2. How do I build a universal binary | 
|  | 60 | ------------------------------------ | 
|  | 61 |  | 
|  | 62 | You can enable universal binaries by specifying the "--enable-universalsdk" | 
|  | 63 | flag to configure:: | 
|  | 64 |  | 
|  | 65 | $ ./configure --enable-universalsdk | 
|  | 66 | $ make | 
|  | 67 | $ make install | 
|  | 68 |  | 
|  | 69 | This flag can be used a framework build of python, but also with a classic | 
|  | 70 | unix build. Either way you will have to build python on Mac OS X 10.4 (or later) | 
|  | 71 | with Xcode 2.1 (or later). You also have to install the 10.4u SDK when | 
|  | 72 | installing Xcode. | 
|  | 73 |  | 
| Ronald Oussoren | 6f6c562 | 2009-12-24 14:03:19 +0000 | [diff] [blame] | 74 | 2.1 Flavours of universal binaries | 
|  | 75 | .................................. | 
|  | 76 |  | 
|  | 77 | It is possible to build a number of flavours of the universal binary build, | 
|  | 78 | the default is a 32-bit only binary (i386 and ppc). The flavour can be | 
|  | 79 | specified using the option ``--with-universal-archs=VALUE``. The following | 
|  | 80 | values are available: | 
|  | 81 |  | 
|  | 82 | * ``32-bit``:   ``ppc``, ``i386`` | 
|  | 83 |  | 
|  | 84 | * ``64-bit``:   ``ppc64``, ``x86_64`` | 
|  | 85 |  | 
|  | 86 | * ``all``:      ``ppc``, ``ppc64``, ``i386``, ``x86_64`` | 
|  | 87 |  | 
|  | 88 | * ``3-way``:	  ``ppc``, ``i386`` and ``x86_64`` | 
|  | 89 |  | 
|  | 90 | * ``intel``:	  ``i386``, ``x86_64`` | 
|  | 91 |  | 
|  | 92 | To build a universal binary that includes a 64-bit architecture, you must build | 
|  | 93 | on a system running OSX 10.5 or later. The ``all`` flavour can only be built on | 
|  | 94 | OSX 10.5. | 
|  | 95 |  | 
|  | 96 | The makefile for a framework build will install ``python32`` and ``pythonw32`` | 
|  | 97 | binaries when the universal architecures includes at least one 32-bit architecture | 
|  | 98 | (that is, for all flavours but ``64-bit``). | 
|  | 99 |  | 
|  | 100 | Running a specific archicture | 
|  | 101 | ............................. | 
|  | 102 |  | 
|  | 103 | You can run code using a specific architecture using the ``arch`` command:: | 
|  | 104 |  | 
|  | 105 | $ arch -i386 python | 
|  | 106 |  | 
|  | 107 | Or to explicitly run in 32-bit mode, regardless of the machine hardware:: | 
|  | 108 |  | 
|  | 109 | $ arch -i386 -ppc python | 
|  | 110 |  | 
|  | 111 | NOTE: When you're using a framework install of Python this requires at least | 
|  | 112 | Python 2.7 or 3.2, in earlier versions the python (and pythonw) commands are | 
|  | 113 | wrapper tools that execute the real interpreter without ensuring that the | 
|  | 114 | real interpreter runs with the same architecture. | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 115 |  | 
|  | 116 | Building and using a framework-based Python on Mac OS X. | 
|  | 117 | ======================================================== | 
|  | 118 |  | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 119 |  | 
| Brett Cannon | 98809b7 | 2004-12-06 06:01:13 +0000 | [diff] [blame] | 120 | 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] | 121 | -------------------------------------------------------------------------- | 
|  | 122 |  | 
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 123 | 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] | 124 | exception of X11/XDarwin-based GUI toolkits all GUI programs need to be run | 
|  | 125 | from a fullblown MacOSX application (a ".app" bundle). | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 126 |  | 
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 127 | While it is technically possible to create a .app without using frameworks you | 
|  | 128 | will have to do the work yourself if you really want this. | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 129 |  | 
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 130 | 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] | 131 | only two places: "/Library/Framework/Python.framework" and | 
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame] | 132 | "/Applications/MacPython <VERSION>" where ``<VERSION>`` can be e.g. "2.6", | 
|  | 133 | "3.1", etc..  This simplifies matters for users installing | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 134 | Python from a binary distribution if they want to get rid of it again. Moreover, | 
|  | 135 | due to the way frameworks work a user without admin privileges can install a | 
|  | 136 | binary distribution in his or her home directory without recompilation. | 
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 137 |  | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 138 | 2. How does a framework Python differ from a normal static Python? | 
|  | 139 | ------------------------------------------------------------------ | 
|  | 140 |  | 
|  | 141 | In everyday use there is no difference, except that things are stored in | 
|  | 142 | a different place. If you look in /Library/Frameworks/Python.framework | 
|  | 143 | you will see lots of relative symlinks, see the Apple documentation for | 
|  | 144 | details. If you are used to a normal unix Python file layout go down to | 
|  | 145 | Versions/Current and you will see the familiar bin and lib directories. | 
|  | 146 |  | 
|  | 147 | 3. Do I need extra packages? | 
|  | 148 | ---------------------------- | 
|  | 149 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 150 | Yes, probably.  If you want Tkinter support you need to get the OSX AquaTk | 
|  | 151 | 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] | 152 | 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] | 153 | PyObjC. | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 154 |  | 
|  | 155 | 4. How do I build a framework Python? | 
|  | 156 | ------------------------------------- | 
|  | 157 |  | 
| Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 158 | 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] | 159 | applications (fullblown OSX .app applications, that is) in | 
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame] | 160 | "/Applications/MacPython <VERSION>", and a hidden helper application Python.app | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 161 | inside the Python.framework, and unix tools "python" and "pythonw" into | 
|  | 162 | /usr/local/bin.  In addition it has a target "installmacsubtree" that installs | 
|  | 163 | the relevant portions of the Mac subtree into the Python.framework. | 
| Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 164 |  | 
| Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 165 | It is normally invoked indirectly through the main Makefile, as the last step | 
|  | 166 | in the sequence | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 167 |  | 
|  | 168 | 1. ./configure --enable-framework | 
|  | 169 |  | 
|  | 170 | 2. make | 
|  | 171 |  | 
|  | 172 | 3. make install | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 173 |  | 
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 174 | This sequence will put the framework in /Library/Framework/Python.framework, | 
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame] | 175 | the applications in "/Applications/MacPython <VERSION>" and the unix tools in | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 176 | /usr/local/bin. | 
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 177 |  | 
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 178 | Installing in another place, for instance $HOME/Library/Frameworks if you have | 
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 179 | no admin privileges on your machine, has only been tested very lightly. This | 
|  | 180 | can be done by configuring with --enable-framework=$HOME/Library/Frameworks. | 
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame] | 181 | The other two directories, "/Applications/MacPython-<VERSION>" and | 
|  | 182 | /usr/local/bin, will then also be deposited in $HOME. This is sub-optimal for | 
|  | 183 | the unix tools, which you would want in $HOME/bin, but there is no easy way to | 
|  | 184 | fix this right now. | 
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 185 |  | 
|  | 186 | 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] | 187 | frameworkinstall is composed of a couple of sub-targets that install the | 
|  | 188 | framework itself, the Mac subtree, the applications and the unix tools. | 
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 189 |  | 
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 190 | There is an extra target frameworkinstallextras that is not part of the | 
| Georg Brandl | 59b4472 | 2010-12-30 22:12:40 +0000 | [diff] [blame^] | 191 | normal frameworkinstall which installs the Tools directory into | 
|  | 192 | "/Applications/MacPython <VERSION>", this is useful for binary | 
| Brett Cannon | 85266da | 2009-12-13 21:15:41 +0000 | [diff] [blame] | 193 | distributions. | 
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 194 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 195 | What do all these programs do? | 
|  | 196 | =============================== | 
| Jack Jansen | 7a1703d | 2002-08-12 20:46:18 +0000 | [diff] [blame] | 197 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 198 | "IDLE.app" is an integrated development environment for Python: editor, | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 199 | debugger, etc. | 
|  | 200 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 201 | "PythonLauncher.app" is a helper application that will handle things when you | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 202 | 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] | 203 | window and runs the scripts with the normal command-line Python. For the | 
|  | 204 | latter it runs the script in the Python.app interpreter so the script can do | 
|  | 205 | GUI-things. Keep the "alt" key depressed while dragging or double-clicking a | 
|  | 206 | script to set runtime options. These options can be set once and for all | 
|  | 207 | through PythonLauncher's preferences dialog. | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 208 |  | 
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 209 | The commandline scripts /usr/local/bin/python and pythonw can be used to run | 
|  | 210 | non-GUI and GUI python scripts from the command line, respectively. | 
| Jack Jansen | 0fdaee7 | 2002-08-02 21:45:27 +0000 | [diff] [blame] | 211 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 212 | How do I create a binary distribution? | 
|  | 213 | ====================================== | 
| Jack Jansen | 8ba4220 | 2002-09-06 20:24:51 +0000 | [diff] [blame] | 214 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 215 | Go to the directory "Mac/OSX/BuildScript". There you'll find a script | 
|  | 216 | "build-installer.py" that does all the work. This will download and build | 
|  | 217 | a number of 3th-party libaries, configures and builds a framework Python, | 
|  | 218 | installs it, creates the installer pacakge files and then packs this in a | 
|  | 219 | DMG image. | 
| Jack Jansen | 4f90137 | 2004-07-15 21:30:41 +0000 | [diff] [blame] | 220 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 221 | The script will build a universal binary, you'll therefore have to run this | 
|  | 222 | 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] | 223 |  | 
| Jack Jansen | 7c0d7ba | 2003-06-20 15:14:08 +0000 | [diff] [blame] | 224 | All of this is normally done completely isolated in /tmp/_py, so it does not | 
|  | 225 | use your normal build directory nor does it install into /. | 
| Jack Jansen | 8ba4220 | 2002-09-06 20:24:51 +0000 | [diff] [blame] | 226 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 227 | Because of the way the script locates the files it needs you have to run it | 
|  | 228 | from within the BuildScript directory. The script accepts a number of | 
|  | 229 | command-line arguments, run it with --help for more information. | 
| Jack Jansen | 8ba4220 | 2002-09-06 20:24:51 +0000 | [diff] [blame] | 230 |  | 
| Ronald Oussoren | f9adc37 | 2010-02-07 11:46:38 +0000 | [diff] [blame] | 231 | Configure warnings | 
|  | 232 | ================== | 
|  | 233 |  | 
|  | 234 | The configure script sometimes emits warnings like the one below:: | 
|  | 235 |  | 
|  | 236 | configure: WARNING: libintl.h: present but cannot be compiled | 
|  | 237 | configure: WARNING: libintl.h:     check for missing prerequisite headers? | 
|  | 238 | configure: WARNING: libintl.h: see the Autoconf documentation | 
|  | 239 | configure: WARNING: libintl.h:     section "Present But Cannot Be Compiled" | 
|  | 240 | configure: WARNING: libintl.h: proceeding with the preprocessor's result | 
|  | 241 | configure: WARNING: libintl.h: in the future, the compiler will take precedence | 
|  | 242 | configure: WARNING:     ## -------------------------------------- ## | 
|  | 243 | configure: WARNING:     ## Report this to http://bugs.python.org/ ## | 
|  | 244 | configure: WARNING:     ## -------------------------------------- ## | 
|  | 245 |  | 
|  | 246 | This almost always means you are trying to build a universal binary for | 
|  | 247 | Python and have libaries in ``/usr/local`` that don't contain the required | 
|  | 248 | architectures. Temporarily move ``/usr/local`` aside to finish the build. | 
|  | 249 |  | 
| Ronald Oussoren | 56d6410 | 2010-04-30 15:13:13 +0000 | [diff] [blame] | 250 |  | 
|  | 251 | Uninstalling a framework install, including the binary installer | 
|  | 252 | ================================================================ | 
|  | 253 |  | 
|  | 254 | Uninstalling a framework can be done by manually removing all bits that got installed, | 
|  | 255 | that's true for both installations from source and installations using the binary installer. | 
|  | 256 | Sadly enough OSX does not have a central uninstaller. | 
|  | 257 |  | 
|  | 258 | The main bit of a framework install is the framework itself, installed in | 
|  | 259 | ``/Library/Frameworks/Python.framework``. This can contain multiple versions | 
|  | 260 | of Python, if you want to remove just one version you have to remove the | 
|  | 261 | version-specific subdirectory: ``/Library/Frameworks/Python.framework/Versions/X.Y``. | 
|  | 262 | If you do that, ensure that ``/Library/Frameworks/Python.framework/Versions/Current`` | 
|  | 263 | is a symlink that points to an installed version of Python. | 
|  | 264 |  | 
|  | 265 | A framework install also installs some applications in ``/Applications/Python X.Y``, | 
|  | 266 |  | 
|  | 267 | And lastly a framework installation installs files in ``/usr/local/bin``, all of | 
|  | 268 | them symbolic links to files in ``/Library/Frameworks/Python.framework/Versions/X.Y/bin``. | 
|  | 269 |  | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 270 | Odds and ends | 
|  | 271 | ============= | 
| Jack Jansen | 408c16f | 2001-09-11 11:30:02 +0000 | [diff] [blame] | 272 |  | 
| Jack Jansen | 1f74ed8 | 2002-09-06 21:00:55 +0000 | [diff] [blame] | 273 | Something to take note of is that the ".rsrc" files in the distribution are | 
|  | 274 | not actually resource files, they're AppleSingle encoded resource files. The | 
|  | 275 | macresource module and the Mac/OSX/Makefile cater for this, and create | 
|  | 276 | ".rsrc.df.rsrc" files on the fly that are normal datafork-based resource | 
|  | 277 | files. | 
| Jack Jansen | 0511b76 | 2001-09-06 16:36:42 +0000 | [diff] [blame] | 278 |  | 
| Brett Cannon | 98809b7 | 2004-12-06 06:01:13 +0000 | [diff] [blame] | 279 | Jack Jansen, Jack.Jansen@cwi.nl, 15-Jul-2004. | 
| Ronald Oussoren | 56d6410 | 2010-04-30 15:13:13 +0000 | [diff] [blame] | 280 | Ronald Oussoren, RonaldOussoren@mac.com, 30-April-2010 |