From KitwarePublic
Jump to navigationJump to search

VTK Eclipse/Pydev

Eclipse with Pydev provides a good development environment for developing Python scripts for VTK. You get Syntax checking/highlighting and code completion and debugging. However in order to integrate VTK we need to do a few extra steps.

This article will show you how to set up the development environment for Windows, Linux and MacOSX.

The folowing discussion assumes that the environment variables have been set and that the user is familiar with or willing to learn the Eclipse IDE.

Environment variables for Linux/MacOS

The environment variables are assuming the following directory structure, so you may need to change paths in the environment variables to suit your own directory structure.


Note: You must set KITWARE_PATH to the root path of your VTK build, for example '/home/username/Code/Kitware'.

Edit ~/.bashrc and add in the following lines.

export KITWARE_PATH=/home/username/Code/Kitware

# For VTK TCL programs.
export TCLLIBPATH='$VTK_DIR/Wrapping/Tcl'
alias vtk='$VTK_DIR/bin/vtk'
# For VTK Python programs.
alias vtkpython='$VTK_DIR/bin/vtkpython'
# NOTE: Change python2.7 to match the Python version used.
# NOTE: For VTK 8.1 and earlier, VTKPYTHONPATH should be set to the following instead

Then do:

source ~/.bashrc

Environment variables for Windows

The environment variables are assuming the following directory structure, so you may need to change paths in the environment variables to suit your own directory structure.


Set the following environment variables:

KITWARE_PATH This will be the root path e.g C:\Kitware or C:\Users\<your username>\Code\Kitware you can choose whatever you prefer here
VTK_BIN %KITWARE_PATH%\build\VTK\Release\bin
PYTHONPATH %VTK_BIN%\Lib\site-packages (or for VTK 8.1 and older: %KITWARE_PATH%\build\VTK\Release\Wrapping\Python)
TCLLIBPATH <root_path>/build/VTK/Release/Wrapping/Tcl/Release

Note that for TCLLIBPATH the path must be fully expanded and \ replaced by /. Replace <root_path> with whatever you used for KITWARE_PATH replacing \ with / e.g C:/Kitware.

You will need to add the following path to the PATH environment variable:


In Windows these are set by going to Control Panel|All Control Panel Items|System and selecting "Advanced System Settings". Then select the Advanced tab and click on Environment Variables.

Setting up Eclipse and Pydev

You must have Java installed, either JRE or JDK, download and install from http://www.java.com.

Download Eclipse Classic from http://www.eclipse.org/downloads/

Unzip it and place the eclipse folder in a suitable place.

Additional steps for Linux

Go to the eclipse folder.

Check eclipse.ini and make sure that, if you have manually installed Java, the openfile section looks something like this:


Of course replace /usr/local/jdk/jdk1.7.0_03/bin/java with the path to the java version you installed.

Create a script, called eclipse.sh, with the following content:

# Start eclipse with some environment variables set.

export KITWARE_PATH=/home/username/Code/Kitware


Remember to change KITWARE_PATH to the root path of your VTK build, for example '/home/username/Code/Kitware' and to change <path_to_eclipse> to the path to the path to the eclipse folder. Both these paths must be absolute paths.

Save and mark this as executable.

The purppose of this script is to set the VTK environment variables so that we can run the Python scripts within Pydev.

Now create a file called eclipse.desktop with this content:

[Desktop Entry]
Comment=The Eclipse Development Environment

Once again, change <path_to_eclipse> to point to your eclipse directory, then save the file. It will appear as a file called Eclipse and will have the eclipse logo. Now right-click on the file and mark it as executable.

Thw purpose of this is to enable the user to just click on Eclipse and everything will be set up for VTK.

From now on, to run eclipse, click on this file called Eclipse. You can copy and paste it anywhere you like because the paths are absolute. For example you might place it on your desktop.

Installing Pydev

Then start eclipse and install Pydev, see: http://www.pydev.org/ for instructions on how to do this.

Pydev project configuration

Once the previous steps have been completed you can start eclipse and create a Pydev project. The environment variables will have been set automatically in Windows and, if you are using Linux, they should be set automatically be executing either eclipse.sh or Eclipse in the eclipse folder.

After you create your Pydev project you will need to edit PYTHONPATH to include the paths to VTK. To do this right-click on the project, select "Properties" then click on the "External Libraries" tab and add the full paths to the following folders in your build directory:


Once this is done you will be able to edit and run any python script in your project.