Changes for compilation on osx. Crucially, I changed add_python_export()...

... to a function to keep local variable scope