- May require the special #!pythonpath line at the top for some servers
- Configure sys.path only if needed to see modules in other directories
- Use Unix end-of-line conventions if your server rejects DOS format
- Flush output buffers if required, or to send portions of the reply periodically
Even if you must use a server machine configured by someone else, most of the ma-
chine’s conventions should be easy to root out during a normal debugging cycle. As
usual, you should consult the conventions for any machine to which you plan to copy
these example files.
Finding Python on remote servers
One last install pointer: even though Python doesn’t have to be installed on any cli-
ents in the context of a server-side web application, it does have to exist on the server
machine where your CGI scripts are expected to run. If you’re running your own server
with either the webserver.py script we met earlier or an open source server such as
Apache, this is a nonissue.
But if you are using a web server that you did not configure yourself, you must be sure
that Python lives on that machine. Moreover, you need to find where it is on that
machine so that you can specify its path in the #! line at the top of your script. If you
are not sure if or where Python lives on your server machine, here are some tips:
- Especially on Unix systems, you should first assume that Python lives in a standard
place (e.g., /usr/local/bin/python): type python (or which python) in a shell window
and see if it works. Chances are that Python already lives on such machines. If you
have Telnet or SSH access on your server, a Unix find command starting at /usr
may help. - If your server runs Linux, you’re probably set to go. Python ships as a standard
part of Linux distributions these days, and many websites and Internet Service
Providers (ISPs) run the Linux operating system; at such sites, Python probably
already lives at /usr/bin/python. - In other environments where you cannot control the server machine yourself, it
may be harder to obtain access to an already installed Python. If so, you can relocate
your site to a server that does have Python installed, talk your ISP into installing
Python on the machine you’re trying to use, or install Python on the server machine
yourself.
If your ISP is unsympathetic to your need for Python and you are willing to relocate
your site to one that is, you can find lists of Python-friendly ISPs by searching the Web.
And if you choose to install Python on your server machine yourself, be sure to check
out the Python world’s support for frozen binaries—with it, you can create a single
executable program file that contains the entire Python interpreter, as well as all the
standard library modules. Assuming compatible machines, such a frozen interpreter
might be uploaded to your web account by FTP in a single step, and it won’t require a
Climbing the CGI Learning Curve| 1145