Recently I’ve been dabbling in python and I wanted to figure out a way to get it working in xulrunner. My guide assumes you already know the basics of making a xulrunner application – see this guide first otherwise. The two main things to really worry about are:
- build the source for xulrunner
- build python xpcom/dom into xulrunner
Step One
Checkout the client script from any directory (for these purposes i’ll say “/home/mark/development”):
cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot co mozilla/client.mk
This will checkout the client.mk file which will be used to get the mozilla source. A new directory will be created “mozilla” and you’ll find “client.mk” inside.
Step Two
Once step one is completed, change into the mozilla directory where the client.mk file is and create a new file called “.mozconfig”. It is important to be named exactly how it sounds,dot-mozconfig. This is the configuration file that will be used to checkout the specific source code that you want (xulrunner) and build it with the appropriate flags enabled. This is mine:
ac_add_options –disable-optimize –enable-debug
mk_add_options MOZ_OBJDIR=@topsrcdir@/obj-xulrunner
mk_add_options MOZ_BUILD_PROJECTS=”xulrunner”
mk_add_options MOZ_CO_PROJECT=”xulrunner”
ac_add_app_options xulrunner –enable-application=xulrunner
ac_add_options –enable-default-toolkit=cairo-gtk2
ac_add_options –disable-javaxpcom
ac_add_options –enable-extensions=python,default
ac_add_options –enable-svg
ac_add_options –enable-xft
ac_add_options –disable-testsExplanation of some of the key entries:
ac_add_options –enable-extensions=python,default | This tells the build script to checkout and build both the python/xpcom and python/dom code. You’re probably wondering what the difference is, and it’s pretty straightforward – python/dom is for using python instead of javascript for your xul handling; python/xpcom is to be able to embed python in an xpcom module.
ac_add_options –enable-default-toolkit=cairo-gtk2 | This is a MUST for linux-based systems. You’ll get compile errors if you don’t!
Step Three
Save the .mozconfig file and then execute:
make -f client.mk checkout
This will checkout all the xulrunner source, python source, and anything else relevant to building based on what you put in the .mozconfig file. I enabled svg just because I wanted to play around with that too
Now, normally at this stage you’d go on to compiling the source but as a result of a bug you’ll need get the following patch and apply it before you start the build:
Please read mozilla bug #392210 for detailed explanation why. The short and sweet is that the Makefile for linux screws up when trying to build the python object file.
Step Four
Time to build the source! Execute the following:
make -f client.mk build
This may take a while.
![]()
Step Five
Change into your mozilla object dir – this was set using:
mk_add_options MOZ_OBJDIR=@topsrcdir@/obj-xulrunner
In this case it will be “/home/mark/development/mozilla/obj-xulrunner/xulrunner”. Now execute the following command:
make package
You don’t really need this to do initial development but I like to do it anyways and then move the whole xulrunner package over to a working project dir so that I can run my application in it’s own space without relying on my mozilla/obj directory. This will probably take a while on your computer.
Step Six
Now you’ve successfully built xulrunner with python available for scripting! Copy the dist/xulrunner directory to your project xulrunner directory:
cp -a “/home/mark/development/mozilla/obj-xulrunner/xulrunner/dist/xulrunner” “/home/mark/development/my_cool_project/”
You’ll have a fully encapsulated “xulrunner” platform to build your first python xulrunner-based app! Hold on tho, you’re not quite done. You now need to setup some enivronment variables.
Step Seven
I put the following into a function called “env_coolproj” inside my .bashrc so that when I want to do development on this cool project, I can just execute “env_coolproj; cd $c” and it will setup all the environment variables for me nicely and cd’s me to the main application root directory. I have setup my project using subversion so I’ve followed the standard svn repository layout.
export COOL_PROJECT_DEV_DIR=/home/mark/development/my_cool_project
export PYTHONPATH=$PYTHONPATH:$COOL_PROJECT_DEV_DIR/my_cool_project/xulrunner/python MOZILLA_FIVE_HOME=$COOL_PROJECT_DEV_DIR/trunk/my_cool_project/xulrunner/
export LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
export c=$COOL_PROJECT_DEV_DIR/trunk/my_cool_project
Now you’ve got a setup ready for python development! The only thing you need to change in your xul to switch from javascript to python scripting is add the script-type=”application/x-python” to the window/page element (the first element not including the <?xml/> tags), and add <script type=”application/x-python”src=”chrome://mycoolproj/content/main.py”/> inside of that element.

[...] wanted to build Python scripting natively into Xulrunner. I searched around and eventually found a fix sitting at Activestate (thanks [...]
If you are running a current version of ubuntu or any of it’s derivatives, just use synaptic & install xulrunner, pyxpcom, ect…
There is a python import bug, here is the workaround.
https://bugs.launchpad.net/ubuntu/+source/xulrunner/+bug/111833
Cheers