|
Graham Dumpleton
graham.dumpleton at gmail.com
Tue Jan 13 01:36:28 EST 2009
What version of Python are you using? It is possible that if using version of Python newer than what that stuff was originally written against, that it is misbehaving. Have seen one other report of odd stuff happening. I don't use mod_python any more and don't really have time to go digging in to why. Really don't understand why people even want to keep writing stuff to mod_python specific APIs when better options exist these days for Python web applications. Graham 2009/1/13 Tim Valenta <tonightslastsong at gmail.com>: >> You should be able to add multiple directories and so long as a single >> Python module code file, should be found even when using 'import'. > > I tried adding my 'subDir'' to the path, so that it looks like this: > PythonOption mod_python.importer.path "['~' , '~/include/']" > My 'import' keyword attempts still failed when trying to import across > this 'include' folder into a specific module file residing there. > > I simplified the experiment down to the above importer.path, and just > ./A.py which uses a keyword 'import' to try to grab C.py from this > 'include' folder. This had surprisingly still lead to failure to find > the module. > >> 2009/1/13 Tim Valenta <tonightslastsong at gmail.com>: >>> Thank you for the links-- they prove useful. >>> >>> Capitalization shouldn't be an issue here... When I began learning >>> Unix a good while back, I quickly cast off relying on the OS to >>> 'figure it out'. I've been keeping everything case sensitive. >>> >>> Backing up to something foundational: I seem to be able to use the >>> import_module() method without problems now, but practically any use >>> of standard python 'import'/'from' keywords fails. The only success I >>> get is when the desired module is in the same directory as the one >>> trying to use the 'import' keyword. Does this stem from the fact that >>> import_module isn't look for packages, but rather specific files? Is >>> it for that reason that I can't use >>> from subDir import C >>> or, the equally broken, >>> import subDir.C >> >> Packages not supported with mod_python module importer, so these fall >> through import_module and uses standard Python import mechanism. >> >>> Jiggering around with adding more entries in importer.path to my >>> subdirectories doesn't seem to have any effect. >> >> You should be able to add multiple directories and so long as a single >> Python module code file, should be found even when using 'import'. >> >> Graham >> >>> If the 'import' >>> keyword really is bound to it's working directory only, I will likely >>> in fact have to use import_module() is several places, rather than >>> just at the head of the request (./A.py) >>> >>> Despite my general lack of success, I appreciate the comments you've >>> made along the way. >>> >>> Tim >>> >>> On Mon, Jan 12, 2009 at 10:40 PM, Graham Dumpleton >>> <graham.dumpleton at gmail.com> wrote: >>>> 2009/1/13 Tim Valenta <tonightslastsong at gmail.com>: >>>>>> You just need to ensure you set mod_python's own module search path, >>>>>> ie. mod_python.importer.path >>>>> >>>>> And yet, as I've now removed my www directory from my PythonPath, I >>>>> actually get limited functionality out of the mod_python imports. >>>>> I've got my apache conf file globally applying the option: >>>>> >>>>> PythonOption mod_python.importer.path "['~']" >>>>> Also have tried using an absolute path, which is producing the same >>>>> functionality: >>>>> PythonOption mod_python.importer.path "['V:/www/']" >>>>> >>>>> My main module ('A') is requested by Apache in my browser, which uses >>>>> import_module to find and import file B. File B is in the same >>>>> directory as A, and they only way it was found was through my apache >>>>> conf noted above. This part works just fine, but two cases develop >>>>> from here: >>>>> >>>>> 1) If I use module B to import a third module 'C', I can't seem to >>>>> make it find module C if it's in a subdirectory. For instance, doing >>>>> either 'import subDirectory.moduleC' or doing >>>>> 'apache.import_module("subDirectory/moduleC")' results in a failure to >>>>> find the module. Note that in this case of subdirectories, I'm >>>>> intentionally avoiding absolute paths to reach my modules. I only >>>>> want to get absolute in my Apache conf. On the flip side, if module C >>>>> is in the same local directory as A and B, then mod_python finds >>>>> module C just fine. >>>> >>>> Try: >>>> >>>> apache.import_module("./subDirectory/moduleC.py") >>>> >>>>> 2 ) If I place C in the same directory as A and B, so that mod_python >>>>> finds it, I tried using the natural Python 'import' keyword in B to >>>>> import C. According to what I understand, this should be fine for >>>>> auto-reloading, since A imports B via import_module, and so then B can >>>>> use either importing strategy to get C in the picture because >>>>> mod_python uses import_module behind the scenes anyway. In this >>>>> setup, my caching issue remains, and changes to C are definitely not >>>>> reflected in apache until a server restart. Again note that it >>>>> doesn't matter if I make B use the 'import' keyword or the >>>>> apache.import_module() method. Both result in failure to reload. >>>>> >>>>> I can't seem to diagnose what's even wrong, since the only reason >>>>> module A, B, or C is being found in the first place is because of my >>>>> importer.path variable is set in httpd.conf. I've been using >>>>> practically empty files to test this. Each file contains no more than >>>>> 5 lines to get the modules imported and then to write out a >>>>> confirmation to the screen that it worked. >>>>> >>>>> Wisdom to offer? >>>> >>>> Yes, from memory the module importer isn't properly case insensitive >>>> on Windows or MacOS X where file systems is case insensitive. Thus, >>>> make sure your imports match exactly the case of the directories/files >>>> in the file system. >>>> >>>> Also, use: >>>> >>>> from mod_python import apache >>>> apache.log_error('__name__ = %s' % repr(__name__)) >>>> apache.log_error('__file__ = %s' % repr(__file__)) >>>> >>>> in modules so that information about imported files is logged as |