More fixes for doc building with python 3

In #1361, @cjmayo pointed out some extra fixes that needed to be implemented to make doc building under python 3 work properly. These have been modified to not break backward compatibility with doc building in python 2.