Building VirtualBox on Mac OS X Lion with Python Bindings

After building VirtualBox with VNC support in my previous post I discovered two problems with that installation (VirtualBox 4.1.2 on Mac OS X Lion 10.7):

  1. SDK was not installed by default, import vboxapi from python failed.
  2. VBox Python bindings were built for python 2.6 and segfaults on python 2.7

I contacted some guys on #vbox-dev on IRC and it what happened is that VirtualBox 4.1.2 was not built for Lion and all build scripts are configured for 10.6. So, I decided to hack my way around for the second time to fix the two issues.

To cut the very long story short, you need to create your own port local repository like how I described in that post and remove the virtualbox directory inside emulators/ and replace it with the patched port (Edit: You don't need this file anymore since the patch is already applied to macports now)

Steps to do download and extract are:

cd ~/ports/emulators  
curl -O ""  
tar vxzf virtualbox-vnc-lion.tar.gz  

The you should just try to install virtualbox again:

sudo port install virtualbox +vnc +vde2  

After installation you should be able immediately to use the Python APIs, open iPython and try the following:

import vboxapi  
mgr = vboxapi.VirtualBoxManager(None, None)  

If this code succeeded without throwing any exceptions then you should be really happy :)

I've also created a relevant ticket on MacPorts for that 31328

Update: The ticket was fixed and you do not need to apply any patches anymore. This post is here for historical reasons only!

comments powered by Disqus