Clodoaldo
clodoaldo.pinto.neto at gmail.com
Fri Dec 1 11:28:18 EST 2006
2006/12/1, Jim Gallacher <jpg at jgassociates.ca>: > Clodoaldo wrote: > > 2006/12/1, Graham Dumpleton <grahamd at dscpl.com.au>: > >> > >> The third option is to not use a package. If you created the package > >> merely > >> out of convenience to provide a namespace for the modules, this should > >> be okay. Thus, remove the empty __init__.py file so that it isn't > >> actually a > >> package anymore. Then, change: > >> > >> from lib import HTMLBuilder > >> > >> to: > >> > >> from mod_python import apache > >> > >> HTMLBuilder = apache.import_module('~/lib/HTMLBuilder.py') > >> > >> This is using the mod_python module importer directly to import the > >> module > >> by path. The '~/' prefix to the path is special and is understood by the > >> module importer to be the directory that the active Python*Handler > >> directive > >> was specified for. > >> > >> > >> A fourth option is to again remove the package __init__.py file so it > >> isn't > >> really a package anymore, but also move the directory to somewhere > >> outside > >> of the document tree. In order to find the modules though, the PythonPath > >> directive is NOT used and instead the new module importers own search > >> path is set. For example: > >> > >> PythonOption mod_python.importer.path "['/some/path/lib']" > >> > >> The module importer path SHOULD NOT mention sys.path, it should instead > >> be a distinct list of directories where only the new module importer > >> will look. > >> Because the 'lib' directory is include and the contents of the > >> directory will be > >> searched, can just say: > >> > >> import HTMLBuilder > >> > >> If for some reason you wanted to do it this way, but not move the > >> directory > >> outside of the document tree, you could also say: > >> > >> PythonOption mod_python.importer.path "['~/lib']" > >> > >> Here the '~/' prefix is again used so you don't have to have an > >> absolute path. > >> When used it will be expanded to the directory the handler was > >> specified for. > >> > >> > >> Anyway, hope I haven't confused you too much. > >> > > > > Your message is not confusing. It came in a good time and it clears > > some confusion i had. But something is not working for me. Using > > mod_python 3.3 in FC6. > > > > I'm trying to import a module with both the third and fourth > > techniques you described but I'm having errors. > > > > This is the Virtual host config: > > > > ServerName carconsumption.s0 > > DocumentRoot /var/www/html/carconsumption.com > > SetHandler mod_python > > PythonHandler mod_python.publisher > > PythonDebug On > > PythonOption mod_python.importer.path "['~/mod']" > > PythonImport db_connection carconsumption.s0 > > > > The module "constants" is in the mod directory under the document root: > > > > [cpn at s0 mod]$ pwd > > /var/www/html/carconsumption.com/mod > > [cpn at s0 mod]$ ll constants.py > > -rwxr----- 1 cpn apache 28675 Nov 29 17:42 constants.py > ^^^^^ > possible permission problem - apache can't read this file unless > your apache process is running as user cpn. > Yes, apache can read it. apache is the group to which the file is assigned and a 740 permission, as it is, gives the group the reading right. To make sure I chmoded it to 777 and still the same error. Regards, -- Clodoaldo Pinto Neto
|