Python 3 compatibility

Added import guards for python 3 compatibility