Fix code to run on recent distributions

This pull request fixes 2 issues:
- Some distros (for example, Arch Linux) set /usr/bin/python to python 3, which breaks scripts which expect it to be python 2.
- PEP 0263 requires an encoding specification if a file contains non-ASCII characters