Building PyXPCOM

Installing Python

PyXPCOM Requirements

PyXPCOM requires Python 2.3 or later (Python 2.3 and 2.4 have both been recently tested).

PyXPCOM requires access to a shared Python library.

Linux

For Linux users, the build script should check if you have a suitable shared library version of Python. Jump to Compiling Mozilla, and if you receive an error telling you a shared Python can not be located, then you'll need to compile Python with --enable-shared as outlined below.

Recent Fedora and Ubuntu builds

These distributions generally have a shared Python already available.

Gentoo systems

Building a shared Python library seems to only be possible with python-2.3* or later, so you'll need to upgrade if you're using python-2.2* or earlier. For ebuilds python-2.3* and later the shared library is built and installed by default.

FreeBSD

Mac OS X

For OS X 10.3 and 10.4 users, the Python 2.3 Framework is already available. If you want to build against Python 2.4, you will need to build your own from source, build via DarwinPorts or Fink, or install either MacPython or ActivePython. You can then skip to Compiling Mozilla. If you want to distribute your application, you might prefer to use the built-in Python 2.3 Framework at first, since embedding the Python Framework into an application bundle may take some non-standard customizations to the Python build scripts.

Windows

The official Python installer for Windows installs the shared version of the the library automatically, so Windows users can simply install Python and skip to Compiling Mozilla.

Other systems

If you
don't
use any of the above systems, get the latest stable Python source tarball from python.org and do:

Compiling Mozilla

Depending on your needs, you will want to pick an appropriate branch of the Mozilla CVS repository.

If you need the most stable code base, and only need Python in backend XPCOM classes, check out Mozilla from the MOZILLA_1_8_BRANCH or the MOZILLA_1_8_0_BRANCH in CVS and build it. Note that this branch may **not** automatically check if you have a suitable shared Python build on Linux systems - you must ensure this yourself.

Use the Mozilla trunk. This has the latest version of XPCOM, incorporating work done on the DOM branches (see below)

You can build PyXPCOM against any of the applications available in the CVS repository. The example below shows building PyXPCOM for SeaMonkey, with Python DOM support. You can also build against XULRunner on the HEAD or MOZILLA_1_8_0_BRANCH by removing "python/dom" from the options and changing the branch in the CVS checkout command.

All Platforms

On all platforms, you should first ensure you can build a vanilla Mozilla
without
any Python extensions. If you can't build Mozilla without Python, you certainly will not be able to build it
with
Python :)

Once you have a successful build, simply enable the extension python (if you are using the 1.8 branch, you must specify python/xpcom). Once this extension has been enabled, rebuild Mozilla.

For example, 1.8 branch users could add a line:

ac_add_options --enable-extensions=python/xpcom,default

Or later versions can add:

ac_add_options --enable-extensions=python,default

to your .mozconfig file.

Nominating the Python version

The configure script will attempt to locate a Python version to use. In most cases, all you need to do is ensure the Python version you wish to use is on your PATH before configuring Mozilla.

Alternatively, you can also set a PYTHON environment variable that points to a Python executable (not a directory - it must be a Python executable). If set, the configure script will use the Python pointed to by the variable.

You can confirm what Python is being used by carefully watching the configure process. You should see a message similar to:

Building PyXPCOM using Python-2.4 from c:/Python24

Windows/MSVC users: make sure you don't use cygwin's Python. It is likely to cause compilation errors later.

Linux and OS X

There are no special considerations for Linux. Below is an example build session on Linux, building the trunk.

Windows

There are no special build considerations for Windows. Follow the generic instructions above regarding --enable-extensions in your .mozconfig file.

Note that you'll get build problems if you try to make a debug build of Mozilla using the release version of Python. Building in this configuration is still possible, but not without certain workarounds (one of which is commenting out #define Py_DEBUG in <tt>pyconfig.h</tt>).