Is that OK to leave a small endless loop script running on server?

how to get apache called python scripts working

  • 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 http://ask.metafilter.com/48024/My-pythons-breath-smells-like-ImportError 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.

  • Answer:

    .pth files are how I do this. http://docs.python.org/inst/search-path.html 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 http://docs.python.org/lib/module-site.html module's documentation.

brent_h at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

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"

breaks the guidelines?

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.

breaks the guidelines?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.