fix random crashes on python 3.x

This fixes segfaults I was having when using PyCall with Python 3.x.  Also fixes https://github.com/stevengj/PyPlot.jl/issues/9.