blob: b6bdc644d2b7295ef37da7c014911c96ce95c959 [file] [log] [blame]
Jack Jansen0fdaee72002-08-02 21:45:27 +00001Building and using a framework-based Python on Mac OS X.
2--------------------------------------------------------
3
4This document provides a quick introduction to framework-based Python.
5It is rather terse and probably incomplete, please send me feedback.
6
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
18only two places: /Library/Framework/Python.framework and /Applications/Python.
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
242. How does a framework Python differ from a normal static Python?
25------------------------------------------------------------------
26
27In everyday use there is no difference, except that things are stored in
28a different place. If you look in /Library/Frameworks/Python.framework
29you will see lots of relative symlinks, see the Apple documentation for
30details. If you are used to a normal unix Python file layout go down to
31Versions/Current and you will see the familiar bin and lib directories.
32
333. Do I need extra packages?
34----------------------------
35
36Yes, probably. If you want to be able to use the PythonIDE you will need to
Jack Jansen1f74ed82002-09-06 21:00:55 +000037get Waste, an all-singing-all-dancing TextEdit replacement, from
38www.merzwaren.com. It will unpack into a folder named something like "Waste
392.1 Distribution". Make a symlink called "waste" to this folder, somewhere
40beside your Python source distribution (it can be "../waste", "../../waste",
41etc).
Jack Jansen0fdaee72002-08-02 21:45:27 +000042
Jack Jansen1f74ed82002-09-06 21:00:55 +000043If you want Tkinter support you need to get the OSX AquaTk distribution. If
44you want wxPython you need to get that. If you want Cocoa you need to get
45pyobjc. Because all these are currently in a state of flux please refer to
Jack Jansen0fdaee72002-08-02 21:45:27 +000046http://www.cwi.nl/~jack/macpython.html, which should contain pointers to more
47information.
48
494. How do I build a framework Python?
50-------------------------------------
51
Jack Jansen21ed16a2002-08-02 14:11:24 +000052This directory contains a Makefile that will create a couple of python-related
Jack Jansen1f74ed82002-09-06 21:00:55 +000053applications (fullblown OSX .app applications, that is) in
54/Applications/Python, and a hidden helper application Python.app inside the
55Python.framework, and unix tools "python" and "pythonw" into /usr/local/bin.
56In addition it has a target "installmacsubtree" that installs the relevant
57portions of the Mac subtree into the Python.framework.
Jack Jansen0511b762001-09-06 16:36:42 +000058
Jack Jansen21ed16a2002-08-02 14:11:24 +000059It is normally invoked indirectly through the main Makefile, as the last step
60in the sequence
Just van Rossumb7dd4942002-09-16 20:18:27 +0000611. ./configure --enable-framework
Jack Jansen21ed16a2002-08-02 14:11:24 +0000622. make
633. make frameworkinstall
Jack Jansen0fdaee72002-08-02 21:45:27 +000064
Jack Jansen1f74ed82002-09-06 21:00:55 +000065This sequence will put the framework in /Library/Framework/Python.framework,
66the applications in /Applications/Python and the unix tools in /usr/local/bin.
Jack Jansen7a1703d2002-08-12 20:46:18 +000067
Jack Jansen1f74ed82002-09-06 21:00:55 +000068Building in another place, for instance $HOME/Library/Frameworks if you have
69no admin privileges on your machine, has only been tested very lightly. This
70can be done by configuring with --enable-framework=$HOME/Library/Frameworks.
71The other two directories, /Applications/Python and /usr/local/bin, will then
72also be deposited in $HOME. This is sub-optimal for the unix tools, which you
73would want in $HOME/bin, but there is no easy way to fix this right now.
Jack Jansen7a1703d2002-08-12 20:46:18 +000074
Jack Jansen1f74ed82002-09-06 21:00:55 +000075Note that there are no references to the actual locations in the code or
76resource files, so you are free to move things around afterwards. For example,
77you could use --enable-framework=/tmp/newversion/Library/Frameworks and use
78/tmp/newversion as the basis for an installer or something.
Jack Jansen7a1703d2002-08-12 20:46:18 +000079
80If you want to install some part, but not all, read the main Makefile. The
Jack Jansen1f74ed82002-09-06 21:00:55 +000081frameworkinstall is composed of a couple of sub-targets that install the
82framework itself, the Mac subtree, the applications and the unix tools.
Jack Jansen7a1703d2002-08-12 20:46:18 +000083
Jack Jansen1f74ed82002-09-06 21:00:55 +000084If you want to run the Makefile here directly, in stead of through the main
85Makefile, you will have to pass various variable-assignments. Read the
86beginning of the Makefile for details.
Jack Jansen7a1703d2002-08-12 20:46:18 +000087
Jack Jansen0fdaee72002-08-02 21:45:27 +000088
895. What do all these programs do?
90---------------------------------
91
92PythonIDE.app is an integrated development environment for Python: editor,
93debugger, etc.
94
95PythonLauncher.app is a helper application that will handle things when you
96double-click a .py, .pyc or .pyw file. For the first two it creates a Terminal
Jack Jansen1f74ed82002-09-06 21:00:55 +000097window and runs the scripts with the normal command-line Python. For the
98latter it runs the script in the Python.app interpreter so the script can do
99GUI-things. Keep the "alt" key depressed while dragging or double-clicking a
100script to set runtime options. These options can be set once and for all
101through PythonLauncher's preferences dialog.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000102
103BuildApplet.app creates an applet from a Python script. Drop the script on it
Jack Jansen1f74ed82002-09-06 21:00:55 +0000104and out comes a full-featured MacOS application. There is much more to this,
105to be supplied later. Some useful (but outdated) info can be found in
106Mac/Demo.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000107
Jack Jansen1f74ed82002-09-06 21:00:55 +0000108The commandline scripts /usr/local/bin/python and pythonw can be used to run
109non-GUI and GUI python scripts from the command line, respectively.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000110
Jack Jansen8ba42202002-09-06 20:24:51 +00001116. How do I create a binary distribution?
112-----------------------------------------
113
114Note: this section is work-in-progress.
115
Jack Jansen1f74ed82002-09-06 21:00:55 +0000116First, to make sure there's no contamination, it is best to remove your
117existing Python installation (clear out /Library/Frameworks/Python.framework
118and /Applications/Python). Also, after build/install is finished check that
119nothing has shown up in those two locations.
Jack Jansen8ba42202002-09-06 20:24:51 +0000120
Jack Jansen1f74ed82002-09-06 21:00:55 +0000121Create a subdirectory of the main python directory, say build-pythondist. In
122there, run
123 ../configure --enable-framework=/tmp/pythondist/Library/Frameworks \
Jack Jansen8ba42202002-09-06 20:24:51 +0000124 LDFLAGS=-Wl,-x
125 make
126 make frameworkinstall
Jack Jansen1f74ed82002-09-06 21:00:55 +0000127This installs a complete distribution set in /tmp/pythondist: in a framework
128build all other pathnames are computed from the framework pathname.
Jack Jansen8ba42202002-09-06 20:24:51 +0000129
Jack Jansenfdf427f2002-09-06 21:55:47 +0000130Optionally you may want to include the full documentation in the binary installer.
131To this end, execute the following commands:
132 python.exe ../Mac/OSX/setupDocs.py build
133 python.exe ../Mac/OSX/setupDocs.py install \
134 --prefix=/tmp/python/Library/Frameworks/Python.framework/Versions/Current
135
Jack Jansen1f74ed82002-09-06 21:00:55 +0000136Note that the unix tools in /tmp/pythondist are wrong, these have to be
137removed, and the installer post-install script should recreate them on the
138target system. Also, the .pyc and .pyo files need to be removed:
Jack Jansen8ba42202002-09-06 20:24:51 +0000139 rm -rf /tmp/pythondist/usr
140 python.exe ../Mac/script/zappycfiles.py /tmp/pythondist
141
Jack Jansenfdf427f2002-09-06 21:55:47 +0000142Finally, create the .pkg file with a commandline like
143 python ../Mac/scripts/buildpkg.py \
144 --Title=MacPython-X \
145 --Version=2.3a0 \
146 --Description="Python for Mac OS X, framework based" \
147 /tmp/pythondist
148This creates a MacPython-X.pkg in the current directory.
Jack Jansen8ba42202002-09-06 20:24:51 +0000149
Jack Jansenfdf427f2002-09-06 21:55:47 +0000150TBD: provide postinstall scripts to precompile .pyc/.pyo files, and to recreate
151the unix programs.
Jack Jansen8ba42202002-09-06 20:24:51 +0000152
1537. Odds and ends.
Jack Jansen0fdaee72002-08-02 21:45:27 +0000154-----------------
Jack Jansen0511b762001-09-06 16:36:42 +0000155
Jack Jansen1f74ed82002-09-06 21:00:55 +0000156The PythonLauncher is actually an Objective C Cocoa app built with Project
157Builder. It could be a Python program, except for the fact that pyobjc is not
158a part of the core distribution, and is not completely finished yet as of this
159writing.
Jack Jansen408c16f2001-09-11 11:30:02 +0000160
Jack Jansen1f74ed82002-09-06 21:00:55 +0000161Something to take note of is that the ".rsrc" files in the distribution are
162not actually resource files, they're AppleSingle encoded resource files. The
163macresource module and the Mac/OSX/Makefile cater for this, and create
164".rsrc.df.rsrc" files on the fly that are normal datafork-based resource
165files.
Jack Jansen0511b762001-09-06 16:36:42 +0000166
Jack Jansen1f74ed82002-09-06 21:00:55 +0000167 Jack Jansen, jack@oratrix.com, 06-Sep-02