Fix crash on exit with closed stdout, issue #50

Thanks to Marc Abramowitz for reporting and fixing.
Use setuptools if present, fall back to distutils.

Fixes issue #7, the setuptools/distutils debate.
Thanks to Marc Abramowitz for providing this solution.