Simple setup of Homebrew, Python, VirtualEnv, Qt (PySide) and VTK on OSX.
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:
-
Install Homebrew:
Homebrew requires Ruby but as this is bundled with OSX, this should install fine.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-
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
-
Install Python:
Use Homebrew to install Python
brew install python
-
Install Qt using Homebrew:
brew install qt
-
Install VTK:
brew install vtk --with-qt
-
Install VirtualEnv:
Use
pip
to install VirtualEnv:pip install virtualenv
-
Make a directory to store your local virtual Python environments:
mkdir ~/VirtualEnv
-
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_REQUIRE_VIRTUALENV=true export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
-
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'
-
Install numpy, scipy & matplotlib:
pip install numpy pip install scipy pip install matplotlib
-
Install PySide:
pip install pyside pyside_postinstall.py -install
TEST
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"
Comments