[Tutor] Re: Help with 500 error on cgi script

D-Man dsh8290@rit.edu
Sun, 18 Mar 2001 18:46:07 -0500


On Sun, Mar 18, 2001 at 12:11:07PM -0800, Sheila King wrote:
| 
| Could not find platform independent libraries <prefix>
| Could not find platform dependent libraries <exec_prefix>
| Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
| 'import site' failed; use -v for traceback
| Traceback (most recent call last):
|   File "listsettings.py", line 5, in ?
|     import cgi
| ImportError: No module named cgi
| 
| 
| So, somehow it is not finding the installed libraries, which are there and do
| work.

I think you are seeing an issue with regards to Unix systems and
users and locating specific versions of things.

| I went to the directory where I have Python-2.0 installed, and
| invoked the interpreter, and at the prompt typed:
| 
| >>>import cgi
| >>>cgi.test()
| 
| and it rattled off its test script. 

This shows that the installation works _with the environment created by
your login scripts_.

| I tried going to my home directory, and editing my .bash-profile directory, so
| that the PATH file includes:
| /big/dom/xthinkspot/Python-2.0
| 
| which is the path to my private install of Python-2.0, but it doesn't seem to
| have helped.

AFAIK Python doesn't use the PATH variable at all (unless you use
os.system).  You need to tell python where the (system) libraries are
using the PYTHONPATH variable.  You can try adding

export PYTHONPATH=/big/dom/xthinkspot/Python-2.0

to your .bash_profile or .bashrc file, but I don't think it will help.
Your script is being invoked by the web server (apache, whatever).  I
think that apache runs as "http" or maybe "nobody".  Scripts will be
run as that user, or possibly a special user with restricted access to
the system (probably named "cgi" or some such).  Is your python
installation world readable and executable?  Also, what is the first
line of the script?  If it is 

#!/usr/bin/env python

as I think I saw, you are using whatever 'python' executable is found
in the path.  Probably 1.5.2 that is installed on the system.  Change
the first line of the script to

#!/big/dom/xthinkspot/Python-2.0/python

to specifically direct execution to your python interpreter.  Again,
I'm not sure this will work.  The #! thing is usually interpreted by
the shell to mean "run this binary (interpreter) on this file".  If
the web server executes interpreters automatically then it will
probably ignore this line.  If it executes it in a shell it should
work.  

Alternatively you may (depending on how the web server is configured)
be able to tell the web server that when it sees a .py (or .py2 or
whatever) extension on files under your ~/public_html (or whatever)
directory it should use /big/dom/xthinkspot/Python-2.0/python to
execute it.

If all else fails, write a simple C/C++ program that simply execs the
proper interpreter on the script giving it the necessary environment.


To determine if I am at all close in diagnosing the problem, make a
simple script that is nothing more than :

#!/usr/bin/env python

import sys

print "Content-type text/html\n"
print sys.version


to show what python version is being used by the web server/CGI
script.

You can also add "-v" to the end of the first line of the script to
get more information in the syslog.

HTH,
-D