[Mailman-Users] module problem

Barry A. Warsaw barry at digicool.com
Sat Mar 24 18:47:27 CET 2001


>>>>> "RMP" == Richard M Pavonarius <rpavonar at cisco.com> writes:

    RMP> Why can Python find the module via the command line but not
    RMP> when it's run as a CGI? I assume the answer has something to
    RMP> do with file permissions or search paths, but I need some
    RMP> pretty specific directions on how to fix it.  I've check the
    RMP> FAQ and the text in cgi.py and didn't find anything useful.

It's almost definitely a search path (or in Python parlance sys.path)
problem.  When run from the command line, Python implicitly imports
site.py which among other things, adds a bunch of directories to
sys.path.  You don't say where you installed kconv, but let's assume
it's in the default Python 2.0 location of
/usr/local/lib/python2.0/site-packages.

-------------------- snip snip --------------------
% python
Python 2.0 (#14, Feb 15 2001, 23:45:39) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/bwarsaw/env/python', '/usr/local/lib/python2.0', '/usr/local/lib/python2.0/plat-linux2', '/usr/local/lib/python2.0/lib-tk', '/usr/local/lib/python2.0/lib-dynload', '/usr/local/lib/python2.0/site-packages', '/usr/local/lib/python2.0/site-packages/PIL']
-------------------- snip snip --------------------

Under normal CLI, you can obviously see the site-packages directory
there, and thus the kconv module would be found.  Now, for performance, Mailman
starts all the cron and CGI scripts with "python -S" to avoid loading
site.py -- which can slow down invocation of Python.  Let's look at
sys.path now...

-------------------- snip snip --------------------
% python -S
Python 2.0 (#14, Feb 15 2001, 23:45:39) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/bwarsaw/env/python', '/usr/local/lib/python2.0/', '/usr/local/lib/python2.0/plat-linux2', '/usr/local/lib/python2.0/lib-tk', '/usr/local/lib/python2.0/lib-dynload']
-------------------- snip snip --------------------

No site-packages, and thus no kconv!

You've got a bunch of options for fixing this.  You could drop kconv
(or a symlink) into one of the paths that will always be on your
sys.path, e.g. /usr/local/lib/python2.0.  Or you could hack
Mailman/mm_cfg.py to add the proper directory onto sys.path, e.g.

import sys
sys.path.append(os.path.join(sys.prefix, 'lib', 'python'+sys.version[:3],
                             'site-packages'))

[Aside to Thomas Wouters: /this/ is my interim solution for mimelib in
2.1a1 :)]

Or you could just remove the -S option from the cron and CGI
invocations.  Doing it for cron is easy, just remove the -S's from
cron/crontab.in and reload it.  Doing it for CGI is trickier because
you have to hack src/common.c and recompile the C wrappers.  Plus,
this will slow down normal operation because of all the other work
site.py does.

Personally, I would (and did! :) add the sys.path hack to mm_cfg.py.

-Barry




More information about the Mailman-Users mailing list