how to get apache called python scripts working
January 18, 2008 11:19 AM   Subscribe

how do I get apache to call local python script that calls modules that are in a different place?

Ok, first off, please excuse my lack of understanding of all things apache.

So, I currently have a python script that is being called from a php page, and the python script is calling a module from a central place on a server. But when I call this script I get a importerror, until I add this line to the python script;

import sys
sys.path.append( '/path/to/python/published/modules')


Then everything works.

How do I get this to work on a global basis ( so I don't have to append every script with these append lines)?

I found this along the same lines, but I can't seem to understand what the resolution was.

I have tried to add the pythonpath to the httpd.conf, with no luck. Here is what I tried to add;

setenv PYTHONPATH "sys.path + ['/path/to/python/published/modules']"


but apachectl configtest shows that that does not work. what do I need to do?

Would mod_python help with this? although I would rather get it working without it if possible.

This is an OSX 10.3 server running apache 1.3, and python 2.4.4.
posted by brent_h to Computers & Internet (3 answers total) 1 user marked this as a favorite
 
I don’t think you can do any computation within the SetEnv directive in httpd.conf. So you probably won’t be able to dynamically determine the pre-existing value of Pythons sys.path. But the PYTHONPATH environment variable is defined to augment Python’s sys.path. So this might work:
SetEnv PYTHONPATH "/path/to/python/published/modules"

posted by breaks the guidelines? at 12:34 PM on January 18, 2008


Also, if you need to specify multiple paths within that variable, the Unix convention is to separate the paths with a colon (:) character. See the ENVIRONMENT VARIABLES section of the Python man page for more info.
posted by breaks the guidelines? at 12:37 PM on January 18, 2008


Best answer: .pth files are how I do this. This page has some info, and this is the money-quote:
The most convenient way is to add a path configuration file to a directory that's already on Python's path, usually to the .../site-packages/ directory. Path configuration files have an extension of .pth, and each line must contain a single path that will be appended to sys.path. (Because the new paths are appended to sys.path, modules in the added directories will not override standard modules. This means you can't use this mechanism for installing fixed versions of standard modules.)
Also check the site module's documentation.
posted by headlessagnew at 12:39 PM on January 18, 2008


« Older Monsoon amp replacement   |   Homemade bed that withstands non-sleep activities Newer »
This thread is closed to new comments.