blob: d618915981996253a9e49908aea17c9043d354ce [file] [log] [blame]
Jack Jansen0fdaee72002-08-02 21:45:27 +00001Building and using a framework-based Python on Mac OS X.
2--------------------------------------------------------
3
Jack Jansen7c0d7ba2003-06-20 15:14:08 +00004This document provides a quick introduction to framework-based Python, its
5advantages, and how to build it.
Jack Jansen0fdaee72002-08-02 21:45:27 +00006
71. Why would I want a framework Python in stead of a normal static Python?
8--------------------------------------------------------------------------
9
Jack Jansen1f74ed82002-09-06 21:00:55 +000010The main reason is because you want to create GUI programs in Python. With the
11exception of X11/XDarwin-based GUI toolkits it appears that all GUI programs
Jack Jansen0fdaee72002-08-02 21:45:27 +000012need to be run from a fullblown MacOSX application (a ".app" bundle).
13
Jack Jansen1f74ed82002-09-06 21:00:55 +000014While it is technically possible to create a .app without using frameworks you
15will have to do the work yourself if you really want this.
Jack Jansen0fdaee72002-08-02 21:45:27 +000016
Jack Jansen1f74ed82002-09-06 21:00:55 +000017A second reason for using frameworks is that they put Python-related items in
Jack Jansen7c0d7ba2003-06-20 15:14:08 +000018only two places: /Library/Framework/Python.framework and /Applications/MacPython-2.3.
Jack Jansen0fdaee72002-08-02 21:45:27 +000019This simplifies matters for users installing Python from a binary distribution
Jack Jansen1f74ed82002-09-06 21:00:55 +000020if they want to get rid of it again. Moreover, due to the way frameworks work
21a user without admin privileges can install a binary distribution in his or
22her home directory without recompilation.
Jack Jansen0fdaee72002-08-02 21:45:27 +000023
Jack Jansen7c0d7ba2003-06-20 15:14:08 +000024Incidentally, the procedure described here is also the procedure that is
25used to create the MacPython binary installer, so the information here
26should theoretically allow you to rebuild that.
27
Jack Jansen0fdaee72002-08-02 21:45:27 +0000282. How does a framework Python differ from a normal static Python?
29------------------------------------------------------------------
30
31In everyday use there is no difference, except that things are stored in
32a different place. If you look in /Library/Frameworks/Python.framework
33you will see lots of relative symlinks, see the Apple documentation for
34details. If you are used to a normal unix Python file layout go down to
35Versions/Current and you will see the familiar bin and lib directories.
36
373. Do I need extra packages?
38----------------------------
39
40Yes, probably. If you want to be able to use the PythonIDE you will need to
Jack Jansen1f74ed82002-09-06 21:00:55 +000041get Waste, an all-singing-all-dancing TextEdit replacement, from
42www.merzwaren.com. It will unpack into a folder named something like "Waste
432.1 Distribution". Make a symlink called "waste" to this folder, somewhere
44beside your Python source distribution (it can be "../waste", "../../waste",
45etc).
Jack Jansen0fdaee72002-08-02 21:45:27 +000046
Jack Jansen1f74ed82002-09-06 21:00:55 +000047If you want Tkinter support you need to get the OSX AquaTk distribution. If
48you want wxPython you need to get that. If you want Cocoa you need to get
49pyobjc. Because all these are currently in a state of flux please refer to
Jack Jansen0fdaee72002-08-02 21:45:27 +000050http://www.cwi.nl/~jack/macpython.html, which should contain pointers to more
51information.
52
534. How do I build a framework Python?
54-------------------------------------
55
Jack Jansen21ed16a2002-08-02 14:11:24 +000056This directory contains a Makefile that will create a couple of python-related
Jack Jansen1f74ed82002-09-06 21:00:55 +000057applications (fullblown OSX .app applications, that is) in
Jack Jansen7c0d7ba2003-06-20 15:14:08 +000058/Applications/MacPython-2.3, and a hidden helper application Python.app inside the
Jack Jansen1f74ed82002-09-06 21:00:55 +000059Python.framework, and unix tools "python" and "pythonw" into /usr/local/bin.
60In addition it has a target "installmacsubtree" that installs the relevant
61portions of the Mac subtree into the Python.framework.
Jack Jansen0511b762001-09-06 16:36:42 +000062
Jack Jansen21ed16a2002-08-02 14:11:24 +000063It is normally invoked indirectly through the main Makefile, as the last step
64in the sequence
Just van Rossumb7dd4942002-09-16 20:18:27 +0000651. ./configure --enable-framework
Jack Jansen21ed16a2002-08-02 14:11:24 +0000662. make
673. make frameworkinstall
Jack Jansen0fdaee72002-08-02 21:45:27 +000068
Jack Jansen1f74ed82002-09-06 21:00:55 +000069This sequence will put the framework in /Library/Framework/Python.framework,
70the applications in /Applications/Python and the unix tools in /usr/local/bin.
Jack Jansen7a1703d2002-08-12 20:46:18 +000071
Jack Jansen7c0d7ba2003-06-20 15:14:08 +000072Installing in another place, for instance $HOME/Library/Frameworks if you have
Jack Jansen1f74ed82002-09-06 21:00:55 +000073no admin privileges on your machine, has only been tested very lightly. This
74can be done by configuring with --enable-framework=$HOME/Library/Frameworks.
Jack Jansen7c0d7ba2003-06-20 15:14:08 +000075The other two directories, /Applications/MacPython-2.3 and /usr/local/bin, will then
Jack Jansen1f74ed82002-09-06 21:00:55 +000076also be deposited in $HOME. This is sub-optimal for the unix tools, which you
77would want in $HOME/bin, but there is no easy way to fix this right now.
Jack Jansen7a1703d2002-08-12 20:46:18 +000078
Jack Jansen1f74ed82002-09-06 21:00:55 +000079Note that there are no references to the actual locations in the code or
80resource files, so you are free to move things around afterwards. For example,
81you could use --enable-framework=/tmp/newversion/Library/Frameworks and use
82/tmp/newversion as the basis for an installer or something.
Jack Jansen7a1703d2002-08-12 20:46:18 +000083
84If you want to install some part, but not all, read the main Makefile. The
Jack Jansen1f74ed82002-09-06 21:00:55 +000085frameworkinstall is composed of a couple of sub-targets that install the
86framework itself, the Mac subtree, the applications and the unix tools.
Jack Jansen7a1703d2002-08-12 20:46:18 +000087
Jack Jansen7c0d7ba2003-06-20 15:14:08 +000088There is an extra target frameworkinstallextras that is not part of the
89normal frameworkinstall which installs the Demo and Tools directories
90into /Applications/MacPython-2.3, this is useful for binary distributions.
91
Jack Jansen1f74ed82002-09-06 21:00:55 +000092If you want to run the Makefile here directly, in stead of through the main
93Makefile, you will have to pass various variable-assignments. Read the
94beginning of the Makefile for details.
Jack Jansen7a1703d2002-08-12 20:46:18 +000095
Jack Jansen0fdaee72002-08-02 21:45:27 +000096
975. What do all these programs do?
98---------------------------------
99
100PythonIDE.app is an integrated development environment for Python: editor,
101debugger, etc.
102
103PythonLauncher.app is a helper application that will handle things when you
104double-click a .py, .pyc or .pyw file. For the first two it creates a Terminal
Jack Jansen1f74ed82002-09-06 21:00:55 +0000105window and runs the scripts with the normal command-line Python. For the
106latter it runs the script in the Python.app interpreter so the script can do
107GUI-things. Keep the "alt" key depressed while dragging or double-clicking a
108script to set runtime options. These options can be set once and for all
109through PythonLauncher's preferences dialog.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000110
111BuildApplet.app creates an applet from a Python script. Drop the script on it
Jack Jansen1f74ed82002-09-06 21:00:55 +0000112and out comes a full-featured MacOS application. There is much more to this,
113to be supplied later. Some useful (but outdated) info can be found in
114Mac/Demo.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000115
Jack Jansen1f74ed82002-09-06 21:00:55 +0000116The commandline scripts /usr/local/bin/python and pythonw can be used to run
117non-GUI and GUI python scripts from the command line, respectively.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000118
Jack Jansen8ba42202002-09-06 20:24:51 +00001196. How do I create a binary distribution?
120-----------------------------------------
121
Jack Jansen4f901372004-07-15 21:30:41 +0000122First go to Mac/OSX and run "python fixversions.py -a" with the Python
123you are going to distribute. This will fix the version numbers and copyright
124strings in the various Info.plist files.
125
Jack Jansen7c0d7ba2003-06-20 15:14:08 +0000126Go to the Mac/OSX/Dist directory. There you find a script "build" that
127does all the work: it configures and builds a framework Python, installs
128it, creates the installer package file and packs this in a DMG image.
Jack Jansen8ba42202002-09-06 20:24:51 +0000129
Jack Jansen7c0d7ba2003-06-20 15:14:08 +0000130All of this is normally done completely isolated in /tmp/_py, so it does not
131use your normal build directory nor does it install into /.
Jack Jansen8ba42202002-09-06 20:24:51 +0000132
Jack Jansen7c0d7ba2003-06-20 15:14:08 +0000133Because the build script locates the Python source tree relative to its own
134pathname you may have to run it with a full pathname. If you are debugging your
135install you can pass one argument: the pathname where the build directory
136is located (i.e. where configure and make will be run), then this directory
137will be saved between runs of the build script. Do *not* specify your normal
138build directory here.
Jack Jansen8ba42202002-09-06 20:24:51 +0000139
Jack Jansen7c0d7ba2003-06-20 15:14:08 +0000140build will ask you whether you have updated the readme file, and it will offer
141to include the full documentation in the installer. That option has not
142been used for a while, and it may not work.
Jack Jansen8ba42202002-09-06 20:24:51 +0000143
Jack Jansen7c0d7ba2003-06-20 15:14:08 +0000144If you need to execute code on the client machine after installing Python
145you can add this to resources/postflight. If you need to do even stranger things
146you have to read Apple's documentation on PackageMaker and read the source
147of Mac/scripts/buildpkg.py.
Jack Jansen8ba42202002-09-06 20:24:51 +0000148
1497. Odds and ends.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000150-----------------
Jack Jansen0511b762001-09-06 16:36:42 +0000151
Jack Jansen1f74ed82002-09-06 21:00:55 +0000152The PythonLauncher is actually an Objective C Cocoa app built with Project
153Builder. It could be a Python program, except for the fact that pyobjc is not
154a part of the core distribution, and is not completely finished yet as of this
155writing.
Jack Jansen408c16f2001-09-11 11:30:02 +0000156
Jack Jansen1f74ed82002-09-06 21:00:55 +0000157Something to take note of is that the ".rsrc" files in the distribution are
158not actually resource files, they're AppleSingle encoded resource files. The
159macresource module and the Mac/OSX/Makefile cater for this, and create
160".rsrc.df.rsrc" files on the fly that are normal datafork-based resource
161files.
Jack Jansen0511b762001-09-06 16:36:42 +0000162
Jack Jansen4f901372004-07-15 21:30:41 +0000163 Jack Jansen, Jack.Jansen@cwi.nl, 15-Jul-2004.