Building VTK User Interfaces: Part 2 – Setting up Your Dev Environment

With the tools and technologies laid out, the next step is to set up a development environment. The end-game here is to have a cross-platform program that runs in both Windows and Linux environments – that way it doesn’t matter where it runs or where you do development. For this project, however, the environment of choice is Ubuntu Linux 14.04. This post will deal with setting up an Ubuntu development environment for VTK+PyQt+LCM and allowing a developer to work out of Eclipse PyDev and IDLE.

— Quick note: We set up the Windows boxes for the ARNerve project and found that the installation for Windows is a little bit of a pain (for LCM mostly). Let me know if you’re looking at doing this and I’ll set up a quick post on it! [Sam] —

These steps are derived from an installation guide that one of the MIT CSAIL group wrote up, so props to Dehann Fourie for working this out into a procedure and ironing out all the headaches! Windows users: I’m an everyday Windows developer, so this is something personally of interest to me. Alucard is looking at setting up a similar environment for Windows and a following post may address the steps required to set it up there. That probably would involve pulling down an already-built Python framework (e.g. Anaconda) and adding in the requisite libraries for VTK and PyQt, so hopefully we have time to discuss that later. If you are also interested in that, please comment below and mention that you’d like that to be a focal point (otherwise my ADD will kick in and it’ll probably end up in the semi- part of the semi-sorted bin :)).

Operating System and Packages

Operating System

In terms of OS, I went with Ubuntu 14.04 because the group I’m working with use it, and to be honest the distro is really smooth. It can be downloaded from Ubuntu. Once you have the ISO, there are three types of approaches for the different types of developers:

  1. ‘I have a few Ubuntu machines already…’ – Awesome, skip past begin and jump straight to the packages
  2. ‘I don’t mind formatting one of my laptops or dual-booting for this project” – You can then burn the DVD and do the install by following the steps in the Ubuntu installer
  3. ‘Erm, rip apart a partition for a Linux Install? Wouldn’t be my first choice…’ – No worries! You can:
    1. Grab some virtual machine (VM) software, e.g. Oracle’s VirtualBox
    2. Mount the downloaded Ubuntu ISO in a clean VM
    3. Follow the install steps and then work out of the VM

Required Packages

Ubuntu Packages

Once you have a working Ubuntu box, you will need to install a few packages. These are:

  • Python 2.7.5 – The language of choice for this project
  • VTK 5.8 – For the 3D part of the UI
  • PyQt4 – For building the 2D interface, PyQt is the link between Python and Qt (Qt is the forms library we’re using in this project)
  • PyQt Designer 4 – For building quick Python UI’s (I’m a big Visual Studio user, the idea of programmatically building a UI freaks me out)
  • Pyuic4 – For building python scripts from PyQt Designer UI’s (found in PyQt4 developer tools)

If you like you can install these individually from ‘Ubuntu Software Center’, or you can open a terminal (press Ctrl+Alt+T in Ubuntu) and run the following as one line ( you will need to fill in your admin password):

sudo apt-get install libvtk5.8-qt4 libvtk5-qt4-dev libvtk5-dev libvtk5.8 python-qt4 python-vtk qt4-designer pyqt4-dev-tools

It should install all those packages and their dependencies, any errors will be shown pretty explicitly (would be surprised if there were any though). It’s true that you can build a lot of these from scratch, and it may be a good idea. However, for beginners that’s a lot of work and prone to end up digging around for fixes when strange stuff happens (e.g. can’t find PYTHONLIBS…). Yes, you might be on VTK 5.8 and not 6.x… but wasn’t that an easy install? If you need features from 6.x you can upgrade at any time in the future, I believe the fundamentals don’t change significantly between 5.8 and 6.x.


LCM installation requires that you compile the source. As far as I can tell a vanilla Ubuntu install with the above packages should have everything needed to successfully install LCM, but if you have any issues please post a comment with the error (probably during the ‘./Configure’ step) and we’ll update this post with the extra packages. To install LCM, open a command prompt (Ctrl+Alt+T), and type in the following lines:

cd ~/Downloads
tar xzf lcm-1.0.0.tar.gz
cd lcm-1.0.0
make -j
sudo make install
sudo ldconfig

Development Environments

Right, so now you should have all the requisite libraries and files. The next step is to install a few IDE’s (Integrated Development Environments) and test that everything works as expected. There are two IDE’s that are useful for developing in Python (…well there are a herd of others, but these are the ones I personally like).


For simple testing you might want to play around in IDLE, it’s clean and easy to work in when doing small projects. For example, it’s a great application for testing a piece of code from a website. To install IDLE, open Ubuntu Software Center and install the ‘idle’ package. You can also open a command prompt and run ‘sudo apt-get install idle’. If you then open IDLE you should see a standard Python console: IDLE Console

Eclipse PyDev

For bigger projects you might want to use PyDev, which is built on the Eclipse framework. PyDev is great for bigger projects, because you can manage multiple files and work in a full IDE. The quick steps are listed below, but more information can be found at PyDev Install:

  • Install Eclipse from the Software Center or using the apt-get call ‘sudo apt-get install eclipse’
  • Open Eclipse
  • Click ‘Install New Software’ under the Eclipse ‘Help’ menu
  • Click ‘Add…’ at the top where it says ‘Work With’
  • Add ‘’
  • Select ‘PyDev’ from the drop-down, and install it
  • Once install, you might want do any updates from the ‘Update Software’ button under ‘Help’
  • If you close the Welcome screen when it restarts, you can select ‘Window’ -> ‘Open Perspective -> ‘PyDev’ to select the Python development perspective
  • There’s great documentation on getting started with Python in PyDev, so it’s skipped in here
  • Quick Tip: To save effort changing perspectives all the time, go to ‘Window’ -> ‘Preferences’ -> ‘General’ -> ‘Perspectives’ and make the PyDev perspective the default (wow switching perspectives all the time gets frustrating!)

Testing Your Environment

The final step is to test you environment. We’ll skip the LCM testing for now and focus on the UI by trying out a slightly modified sample file from the VTK documentation. This sample includes some PyQt so it should test all the components that the UI would need. The original sample can be found at Vtk – EmbedPyQt2. To test the development environment:

  • Open a IDLE instance, and click ‘File’ -> ‘New File’ (or press Ctrl+N)
  • Copy the code from below or from the original VTK sample into the new file
  • Click ‘Run’ -> ‘Run Module’ from the menu of the new file
  • You should see a sphere with a few buttons, and should be able to use the interactive camera to move around the sphere (it’s a great VTK sample, really shows how to lay out all the bits and pieces)
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QApplication
import vtk
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.resize(603, 553)
        self.centralWidget = QtGui.QWidget(MainWindow)
        self.gridlayout = QtGui.QGridLayout(self.centralWidget)
        self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
        self.gridlayout.addWidget(self.vtkWidget, 0, 0, 100, 100)
        self.buttonLeft = QtGui.QPushButton("Left")
        self.gridlayout.addWidget(self.buttonLeft, 96,48,1,1)
        self.buttonRight = QtGui.QPushButton("Right")
        self.gridlayout.addWidget(self.buttonRight, 96,52,1,1)
        self.buttonUp= QtGui.QPushButton("Up")
        self.gridlayout.addWidget(self.buttonUp, 94,50,1,1)
        self.buttonDown = QtGui.QPushButton("Down")
        self.gridlayout.addWidget(self.buttonDown, 98,50,1,1)
        self.buttonFire = QtGui.QPushButton("Fire Torpedo")
        self.gridlayout.addWidget(self.buttonFire, 95,50,3,1)

class SimpleView(QtGui.QMainWindow):
    def __init__(self, parent = None):
        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self) = vtk.vtkRenderer()
        self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
        # Create source
        source = vtk.vtkSphereSource()
        source.SetCenter(0, 0, 0)
        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        # Create an actor
        actor = vtk.vtkActor()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = SimpleView()
    window.iren.Initialize() # Need this line to actually show the render inside Qt

When run, the UI should show something similar to the image below: Vtk with PyQt Sample With that working, there are many guides to the individual components. Some links to review are:

The next step is to start building an Eclipse project, laying out the components, and starting to shape up the UI. This is discussed in the next post on this project. I’m reading up as I go and switching between a gaggle of other projects, but I’ll hopefully have it up by next week!


5 thoughts on “Building VTK User Interfaces: Part 2 – Setting up Your Dev Environment

  1. Lol, I think I got spoilt by VS’s intellisense and Eclipse’s content assist… If it needs to be done, *sigh* okay, but I like something yelling as soon as I miss a semi-colon or messed up a namespace reference :p


  2. Hi Sam. Setting up VTK and PyQt4 in Windows isn’t that hard. I use WinPython and grab the packages I need from Searching that page for ‘PyQt4’ and ‘VTK’ will take you to the right packages. The VTK packages come in two flavours, one built with PyQt and the other without PyQt so you just have to make sure to get the ones with PyQt. AFAIK all the PyQt developer tools are included in Christoph Gohlke’s installer. All the packages are supplied as .exe installers. Most of the time installation is as simple as double clicking the .exe. PyQt4 is the only one that required more work as it prompts you for the root directory of the Python installation. Hope this helps.


    • Hi William,

      That’s great – thanks! Have been talking about adding a section on Windows installation, will write one up this weekend with your info if that’s ok?

      I’m really curious whether the project runs cleanly on both Linux and Windows, another reader – Daniel – is trying it and has success but we haven’t written up the steps quite yet, your info will really help.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s