[mod_python] Re: mod_python and C extensions

Graham Dumpleton graham.dumpleton at gmail.com
Wed Feb 20 15:35:32 EST 2008


In mod_python 3.3.1, Python packages, nor C extension modules will be
found if they reside in the document directory which is the target of
the URL and thus PythonHandler directive. Only .py files are used.
Python packages and C extension modules must be in a physical
directory specified in PythonPath or otherwise on sys.path. It isn't
recommended to be putting the document tree directory in PythonPath
because it causes an overlap between mod_python module importer path
and standard module search path. Thus, put your .so file outside of
the document tree somewhere with that directory in PythonPath, and use
handler .py wrapper in document tree to import it from that location
and relay the call. The two will obviously need to have a different
basename now.

For more details about module importer see import_module() documentation in:

  http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html

Other than that suggestion, need to see the mod_python configuration
from Apache and for you to also say what directory path your files are
in so can relate that to the configuration.

Graham

On 21/02/2008, argriffi <argriffi at ncsu.edu> wrote:
> Hi guys,
>
> I'm having a problem getting Apache and mod_python to use my C extension
> module mymodule.so instead of my raw python module mymodule.py.  Both
> modules have been tested outside of Apache/mod_python.
>
> There is no error when I have mymodule.py in the directory, but when I
> replace it with mymodule.so (in the same directory), I get an error.
> This seems to rule out problems with the python path.
>
> The .py and .so modules that I have tried both have the same owner and
> group, and have the same permissions except that the .so file has
> execute permissions.  This seems to rule out problems with Apache user
> permissions.
>
> I tried some stuff from googling and from BasicsOfModuleImporting and
> ModuleImportingIsBroken, but I've had no luck and I'm about to start
> using CherryPy or something.
>
> Alex
>
>
>
>
>
> Graham Dumpleton wrote:
> > Can you please use the mod_python mailing list to ask questions.
> >
> >   http://mailman.modpython.org/mailman/listinfo/mod_python
> >
> > Your problem though sounds like you need to either set PythonPath, or
> > the file, or directories it is in are not readable to the user that
> > Apache runs as.
> >
> > Graham
> >
> >
> >
> >> Hi,
> >>
> >> I'm using mod_python to provide some web apps, and I recently rewrote
> >> mymodule.py as the C extension mymodule.so.  I was glad to see that it
> >> runs about 100x as fast, but I was unhappy to see that it apparently
> >> cannot be imported when I am using mod_python.  I get the ImportError
> >> "No module named mymodule".  Since I seem to fail at googling, do you
> >> have any tips to help me solve this?
> >>
> >>
> >>
> >>
> >>
> >>
> >>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list