Various style and build fixes.

### Changelog
* Fixed most `pylint` and `flake8` warnings.
* Suppressing `distutils` import error. The outstanding error in Travis will be fixed once #900 is merged.
* Suppressing `py2exe` import error; `py2exe` is installed by configure script.
* Suppressing `py2exe` unused import error; this is the standard way to use it.
* Moved setup code inside a `main` function.