python cgi generates apache exec format error

This is my first attempt at reportlab, a python pdf generator.  I want it to emit the pdf to a browser.  The following program executes okay from the command line, but gives a exec format error in apache.  The execute chmod bit is on.  Please advise.

import cgitb; cgitb.enable()
import cgi
import os
import datetime
import time
import pgdb
import re
import string
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
import sys
from reportlab.lib.units import inch
myCanvas=canvas.Canvas(sys.stdout,pagesize=letter)
width,height=letter
textobject=myCanvas.beginText(0,0)

textobject.setTextOrigin(inch,10*inch)


textobject.textOut("Hello world!")
myCanvas.drawText(textobject)
myCanvas.showPage()
print "Content-type: application/pdf"     # HTML is following
print
myCanvas.save()
astar666Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

efnCommented:
How are you getting to the script through Apache?  Are you trying to use CGI?  What operating system are you using?

I have found with Python CGI scripts under UNIX that I had to put a shebang line at the beginning of the Python script to make it work.  For example:

#!/whereverPythonIs/python

Otherwise, Apache didn't know to run the script with Python.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
efnCommented:
Sorry, I missed the "cgi" in the question title.  The operating system question still applies.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.