The lessons learned after confronting this. Assume a program in "Fred.py" for user "pbrooks".
Did you save your program in your public_html directory (or a subdirectory under public_html) ?
Did you change the file permissions to make it executable?
Test it with the PythonChecker: http://bert.stuy.edu/pbrooks/PythonChecker
Did you test it in the terminal (or windows cmd window): $./Fred.py to see if there are any syntax errors?
Did you test it with url: http://lisa.stuy.edu/~pbrooks/Fred.py ?
Did you spell the filename correctly in the url? (It's Fred.py, not fred.py).
The shebang (first) line in your program file should
be:
#! /usr/bin/python3
Note: Everything that Fred.py prints will be sent to the user's browser
The first thing that your program should do is print
the content-type of the rest of the information that the program will print.
That content-type is "text/html". So...
print ("Content-type: text/html\n")
If you get the following error message when executing
the program (look for the "^M" in the error message):
./Fred.py: /usr/bin/python^M: bad interpreter: No
such file or directory
then the most likely cause is that you've just transferred this
program file from your home Windows laptop, and Windows writes files a
little differently than Unix or Mac. In particular, it ends each line
of a text file with not only the character "\n", but rather the pair of
characters "\r\n". The extra "\r" at the end of the shebang line makes
the Unix shell throw up with the error message you see above. (BTW,
the "^M" is how the Unix shell displays the problematic "\r" character).
How to fix? Execute the following line to fix your Fred.py
file:
~pbrooks/dos2unix Fred.py