[Pythonmac-SIG] Slim Python Framework (under 340 KB compressed)

Adam Eijdenberg adam@switchedonsoftware.com
Sat, 12 Jan 2002 15:42:06 +1100


As promised I had a go at sliming down Python. The objective was to 
create a framework for Python that is suitable for distributing with 
applications that embed Python.

Here's the summary of what I did. First I'll mention that I have only 
just started using all this unix stuff last year after switching to OS 
X, so all you unix guru's will probably have a good chuckle and maybe an 
occasional cringe when you see what I have done.

1) Start off with the standard unix source distribution of Python 2.2.
2) Hack the configure file so that debug information is not built when 
compiling.
3) Configure Python to build as a framework without toolbox glue code.
4) Make and install it in /Library/Frameworks
5) Remove all headers files and related symbolic links.
6) Remove all files in the library folder.
7) Create empty directory (lib-dynload) and empty files (os.py and 
site.py) to keep the python happy.

Results in a folder with size 995126 bytes (according to the Finder).
This zips down to 337 KB, a most acceptable size.

The only real gotcha that's hit me so far is that I removed all Headers 
from the framework, so one might like to keep a version hanging around 
with header files so that you can still compile.

Oh yeah, and no warranties at all. It seems to work for me :).

You can either use the script below to slim your own framework, or if 
you find compiling programs as exciting as I do, then it can downloaded 
from:
http://www.switchedonsoftware.com/python/SlimPython.tar.gz

My extremely amateur shell script (apologies if any lines wrap):

#!/bin/sh
tar zxf Python-2.2.tgz && \
cd Python-2.2 && \
sed -e 's/OPT="-g -O3 -Wall -Wstrict-prototypes"/OPT="-O3 -Wall 
-Wstrict-prototypes"/g' configure > TEMP && \
mv TEMP configure && \
chmod u+x configure && \
./configure --enable-framework --disable-toolbox-glue && \
make && \
make frameworkinstall && \
FRAMEWORK="/Library/Frameworks/Python.framework" && \
VERSION="2.2" && \
rm -r "$FRAMEWORK/Versions/$VERSION/lib/python$VERSION" && \
mkdir "$FRAMEWORK/Versions/$VERSION/lib/python$VERSION" && \
touch "$FRAMEWORK/Versions/$VERSION/lib/python$VERSION/site.py" && \
touch "$FRAMEWORK/Versions/$VERSION/lib/python$VERSION/os.py" && \
mkdir "$FRAMEWORK/Versions/$VERSION/lib/python$VERSION/lib-dynload" && \
rm "$FRAMEWORK/Headers" && \
rm "$FRAMEWORK/Versions/$VERSION/Headers" && \
rm -r "$FRAMEWORK/Versions/$VERSION/include" && \
rm -r "$FRAMEWORK/Versions/$VERSION/man" && \
echo "Done."


Kind regards,
Adam Eijdenberg
Switched on Software