Building PyXPCOM

  • Revision slug: Building_PyXPCOM
  • Revision title: Building PyXPCOM
  • Revision id: 121924
  • Created:
  • Creator: Toddw
  • Is current revision? No
  • Comment Mention that it requires xulrunner 1.9.2; 8 words added, 1 words removed

Revision Content

These are the instructions for building PyXPCOM.

Note: For those wanting to use PyXPCOM within Firefox and/or XULRunner, the PythonExt extension provides prebuilt PyXPCOM bindings for Firefox/XULRunner.

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

Python built from ports (lang/python24) already provides a shared Python library.

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:

tar xjf Python-2.4.2.tar.bz2
cd Python-2.4.2
./configure --enable-shared --prefix=/usr  # Adjust --prefix to install over your current Python
make
sudo make install

Compiling PyXPCOM

You should be familiar with the Mozilla Build Instructions.

  • Download or build the XULRunner SDK (requires the 1.9.2 XULRunner SDK version).
  • Make a pyxpcom directory and cd to it: mkdir pyxpcom; cd pyxpcom
  • Get the PyXPCOM source code using Mercurial: hg clone http://hg.mozilla.org/pyxpcom src
  • Generate the src configure script: cd src;  autoconf2.13; cd ..
  • Make a PyXPCOM build directory: mkdir build; cd build
  • Configure: ../src/configure --with-libxul-sdk=/path/to/libxul-sdk
  • Make: make

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.

Testing PyXPCOM

First test your fresh PyXPCOM build from within Mozilla's runtime environment.

Linux and OS X:

cd suite-debug/dist/bin
export PYTHONPATH=$PYTHONPATH:$HOME/mozilla/suite-debug/dist/bin/python # Adjust this to your PyXPCOM build path
./run-mozilla.sh ./seamonkey -chrome chrome://pyxultest/content 

Windows:

cd dist\bin
set PYTHONPATH=%PYTHONPATH%;C:\mozilla\dist\bin\python
seamonkey.exe -chrome chrome://pyxultest/content 

A window with controls should pop up. Run the tests it contains.

In the same directory you can also perform a simple test of the Python xpcom module from a standalone Python environment.

Linux and OS X:

export MOZILLA_FIVE_HOME=$HOME/mozilla/suite-debug/dist/bin # Adjust this to your Mozilla build path
export LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
python -c 'from xpcom import components; print components.classes{{mediawiki.external('\"@mozilla.org/file/local;1\"')}}' 

Windows:

set PATH=%PATH%;C:\mozilla\dist\bin
set MOZILLA_FIVE_HOME=C:\mozilla\dist\bin
set LD_LIBRARY_PATH=%MOZILLA_FIVE_HOME%
python -c "from xpcom import components; print components.classes{{mediawiki.external('\'@mozilla.org/file/local;1\'')}}" 

You should see output similar to the following:

Type Manifest File: /home/you/mozilla/suite-debug/dist/bin/components/xpti.dat
<xpcom.components._Class instance at 0xb7c1be8c>
nsStringStats
 => mAllocCount:            431
 => mReallocCount:          270
 => mFreeCount:             423  --  LEAKED 8 !!!
 => mShareCount:            450
 => mAdoptCount:              0
 => mAdoptFreeCount:          0

If you see Python error messages instead, make sure $PYTHONPATH is still set the same as in the first test.

{{ languages( { "ja": "ja/Building_PyXPCOM" } ) }}

Revision Source

<p>These are the instructions for building <a href="/en/PyXPCOM" title="en/PyXPCOM">PyXPCOM</a>.</p>
<div class="note"><strong>Note:</strong> For those wanting to use PyXPCOM within Firefox and/or <a class="internal" href="/en/XULRunner" title="En/XULRunner">XULRunner</a>, the <a class="external" href="http://pyxpcomext.mozdev.org/" title="http://pyxpcomext.mozdev.org/">PythonExt</a> extension provides prebuilt PyXPCOM bindings for Firefox/XULRunner.</div>
<h3 id="Installing_Python" name="Installing_Python">Installing Python</h3>
<h4 id="PyXPCOM_Requirements" name="PyXPCOM_Requirements">PyXPCOM Requirements</h4>
<ul> <li>PyXPCOM requires Python 2.3 or later (Python 2.3 and 2.4 have both been recently tested).</li> <li>PyXPCOM requires access to a shared Python library.</li>
</ul>
<h4 id="Linux" name="Linux">Linux</h4>
<p>For Linux users, the build script should check if you have a suitable shared library version of Python. Jump to <a href="/en/Building_PyXPCOM#Compiling_Mozilla" title="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a>, and if you receive an error telling you a shared Python can not be located, then you'll need to compile Python with <code>--enable-shared</code> as outlined <a href="/en/Building_PyXPCOM#Other_systems" title="en/Building_PyXPCOM#Other_systems">below</a>.</p>
<h5 id="Recent_Fedora_and_Ubuntu_builds" name="Recent_Fedora_and_Ubuntu_builds">Recent Fedora and Ubuntu builds</h5>
<p>These distributions generally have a shared Python already available.</p>
<h5 id="Gentoo_systems" name="Gentoo_systems">Gentoo systems</h5>
<p>Building a shared Python library seems to only be possible with <code>python-2.3*</code> or later, so you'll need to upgrade if you're using <code>python-2.2*</code> or earlier. For ebuilds <code>python-2.3*</code> and later the shared library is built and installed by default.</p>
<h4 id="FreeBSD" name="FreeBSD">FreeBSD</h4>
<p>Python built from ports (<code>lang/python24</code>) already provides a shared Python library.</p>
<h4 id="Mac_OS_X" name="Mac_OS_X">Mac OS X</h4>
<p>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 <a class="external" href="http://www.python.org/download/">source</a>, build via <a class="external" href="http://darwinports.opendarwin.org/">DarwinPorts</a> or <a class="external" href="http://fink.sourceforge.net/">Fink</a>, or install either <a class="external" href="http://undefined.org/python/">MacPython</a> or <a class="external" href="http://www.ActiveState.com/">ActivePython</a>. You can then skip to <a href="/en/Building_PyXPCOM#Compiling_Mozilla" title="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a>. 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.</p>
<h4 id="Windows" name="Windows">Windows</h4>
<p>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 <a href="/en/Building_PyXPCOM#Compiling_Mozilla" title="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a>.</p>
<h4 id="Other_systems" name="Other_systems">Other systems</h4>
<p>If you <em>don't</em> use any of the above systems, get the latest stable Python source tarball from <a class="external" href="http://python.org/download/">python.org</a> and do:</p>
<pre>tar xjf Python-2.4.2.tar.bz2
cd Python-2.4.2
./configure --enable-shared --prefix=/usr  # Adjust --prefix to install over your current Python
make
sudo make install
</pre>
<h3 id="Compiling_Mozilla" name="Compiling_Mozilla">Compiling PyXPCOM</h3>
<p>You should be familiar with the <a class="internal" href="/En/Developer_Guide/Build_Instructions" title="En/Developer Guide/Build Instructions">Mozilla Build Instructions</a>.</p>
<ul> <li>Download or build the <a class="internal" href="/en/Gecko_SDK" title="en/Gecko SDK">XULRunner SDK</a> (requires the 1.9.2 XULRunner SDK version).</li> <li>Make a pyxpcom directory and cd to it: mkdir pyxpcom; cd pyxpcom</li> <li>Get the PyXPCOM source code using Mercurial: <code>hg clone <a class=" external" href="http://hg.mozilla.org/pyxpcom" rel="freelink">http://hg.mozilla.org/pyxpcom</a> src</code></li> <li><code>Generate the src configure script: cd src; </code> autoconf2.13; cd ..</li> <li>Make a PyXPCOM build directory: <code>mkdir build; cd <span style="font-family: Verdana,Tahoma,sans-serif;">build</span></code></li> <li>Configure: <code>../src/configure --with-libxul-sdk=/path/to/libxul-sdk</code></li> <li>Make: <code>make</code></li>
</ul>
<h4 id="Nominating_the_Python_version">Nominating the Python version</h4>
<p>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.</p>
<p>Alternatively, you can also set a <code>PYTHON</code> 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.</p>
<p>You can confirm what Python is being used by carefully watching the configure process. You should see a message similar to:</p>
<pre class="eval">Building PyXPCOM using Python-2.4 from c:/Python24
</pre>
<p>Windows/MSVC users: make sure you don't use cygwin's Python. It is likely to cause compilation errors later.</p>
<h3 id="Testing_PyXPCOM" name="Testing_PyXPCOM">Testing PyXPCOM</h3>
<p>First test your fresh PyXPCOM build from within Mozilla's runtime environment.</p>
<p><em>Linux and OS X:</em></p>
<pre>cd suite-debug/dist/bin
export PYTHONPATH=$PYTHONPATH:$HOME/mozilla/suite-debug/dist/bin/python # Adjust this to your PyXPCOM build path
./run-mozilla.sh ./seamonkey -chrome chrome://pyxultest/content </pre>
<p><em>Windows:</em></p>
<pre>cd dist\bin
set PYTHONPATH=%PYTHONPATH%;C:\mozilla\dist\bin\python
seamonkey.exe -chrome chrome://pyxultest/content </pre>
<p>A window with controls should pop up. Run the tests it contains.</p>
<p>In the same directory you can also perform a simple test of the Python <code>xpcom</code> module from a standalone Python environment.</p>
<p><em>Linux and OS X:</em></p>
<pre>export MOZILLA_FIVE_HOME=$HOME/mozilla/suite-debug/dist/bin # Adjust this to your Mozilla build path
export LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
python -c 'from xpcom import components; print components.classes{{mediawiki.external('\"@mozilla.org/file/local;1\"')}}' </pre>
<p><em>Windows:</em></p>
<pre>set PATH=%PATH%;C:\mozilla\dist\bin
set MOZILLA_FIVE_HOME=C:\mozilla\dist\bin
set LD_LIBRARY_PATH=%MOZILLA_FIVE_HOME%
python -c "from xpcom import components; print components.classes{{mediawiki.external('\'@mozilla.org/file/local;1\'')}}" </pre>
<p>You should see output similar to the following:</p>
<pre>Type Manifest File: /home/you/mozilla/suite-debug/dist/bin/components/xpti.dat
&lt;xpcom.components._Class instance at 0xb7c1be8c&gt;
nsStringStats
 =&gt; mAllocCount:            431
 =&gt; mReallocCount:          270
 =&gt; mFreeCount:             423  --  LEAKED 8 !!!
 =&gt; mShareCount:            450
 =&gt; mAdoptCount:              0
 =&gt; mAdoptFreeCount:          0
</pre>
<p>If you see Python error messages instead, make sure <code>$PYTHONPATH</code> is still set the same as in the first test.</p>
<p>{{ languages( { "ja": "ja/Building_PyXPCOM" } ) }}</p>
Revert to this revision