Are you executing the script from the terminal using python or as a shell script? It looks like your machine doesn’t use Python to run it, so you might want to add the shebang at the beginning of your script, e.g.:
#!/usr/bin/env python