Simple setup of Homebrew, Python, VirtualEnv, Qt (PySide) and VTK on OSX.

Sep 2014
Sat 13

Bug & hack free quick install of a Python environment on OSX.

I have recently moved to a new 13" MBP with Retina (a great machine packed with 16gb ram, i7 and SSD) which meant a clean install of my Python development environment. Over the years I've used various methods of doing this, mainly revolving around package managers like Fink and MacPorts. Whilst these approaches do eventually lead to a stable environment, I have found the best approach is using Homebrew. In the instructions below, I also include the installation of VirtualEnv, a very useful tool that allows you to explicitly manage your Python environment(s).

Right let's get started:

  1. Install Homebrew:

    Homebrew requires Ruby but as this is bundled with OSX, this should install fine.

    ruby -e "$(curl -fsSL"
  2. Edit paths ready for Homebrew environments:

    In your ~/.bashrc or ~/.bash_profile

    .bashrc or .bash_profile

    export PATH=/usr/local/bin:/usr/local/sbin:$PATH
  3. Install Python:

    Use Homebrew to install Python

    brew install python
  4. Install Qt using Homebrew:

    brew install qt
  5. Install VTK:

    brew install vtk --with-qt
  6. Install VirtualEnv:

    Use pip to install VirtualEnv:

    pip install virtualenv
  7. Make a directory to store your local virtual Python environments:

    mkdir ~/VirtualEnv
  8. Ensure pip will now only install packages if we are in an activated VirtualEnv:

    Export the following in your ~/.bashrc or ~/.bash_profile

    .bashrc or .bash_profile

    export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
  9. Create and activate a new VirtualEnv:

    Change to the VirtualEnv directory previously created and generate the VirtualEnv

    cd ~/VirtualEnv
    virtualenv --system-site-packages v1
    source v1/bin/activate

    The --system-site-packages is required to inherit the vtk python bindings that homebrew installed in /usr/local/lib.

    As a handy option, you can alias the activation in your ~/.bashrc or ~/.bash_profile

    .bashrc or .bash_profile

    alias v1='source ~/Dropbox/VirtualEnv/v1/bin/activate'
  10. Install numpy, scipy & matplotlib:

    pip install numpy
    pip install scipy
    pip install matplotlib
  11. Install PySide:

    pip install pyside -install


If the above installed correctly, the following imports should NOT return an error.

Marcs-MacBook-Pro: v1
(v1) Marcs-MacBook-Pro: python -c "import vtk, PySide, numpy, scipy, matplotlib"