|
Lee Brown
administrator at leebrown.org
Thu Sep 15 00:27:33 EDT 2005
Greetings!
PythonImport works exactly as advertised for me. I'll show you my setup;
maybe that will shed some light...
Environment:
Apache 2.0.54 (win32/MPM), mod_python 3.1.3, Python 2.3.4, WinXP SP2
In the main section of httpd.conf:
AddHandler mod_python .py
PythonImport site_setup.py crashtest
In the vhosts section of httpd.conf:
<VirtualHost *:80>
ServerName crashtest.leebrown.org
...
PythonPath "sys.path +
['C:/.../crashtest/home/','C:/.../crashtest/config/']"
PythonInterpreter crashtest
PythonHandler import_test
PythonDebug On
...
</VirtualHost>
In site_setup.py:
__all__ = ['basepath', 'siteroot', 'cfg_root', 'doc_root',
'tmp_root', 'py__root']
basepath = 'c:/projects/webdev/sites'
siteroot = basepath + '/crashtest'
cfg_root = siteroot + '/config'
doc_root = siteroot + '/home'
tmp_root = siteroot + '/templates'
py__root = siteroot + '/python'
In import_test.py:
from mod_python import apache
from site_setup import *
def handler(req):
req.content_type = 'text/plain'
req.write(siteroot)
return apache.OK
Which writes "c:/projects/webdev/sites/crashtest" just as expected.
A few observations bear noting:
In my setup, the PythonInterpreter statement comes AFTER the PythonImport
statement. I noticed that some folks had it the other way 'round. I have
no idea if this really makes a difference or not.
The first path added to sys.path is actually redundant; the server or vhost
DocumentRoot path is stealthly added to sys.path by mod_python
Site_setup.py is loaded before PythonPath is evaluated, so it's useless for
locating the imported module. However, site_setup.py is loaded AFTER the
DocumentRoot is added to sys.path, so the imported module can be located in
the DocumentRoot in addition to all the 'standard' Python places.
I have not tried this yet, but with a proper *.pth (python path file) you
~might~ be able to add custom paths that are available when PythonImport
executes.
Best Regards,
Lee E. Brown
(administrator at leebrown.org)
-----Original Message-----
From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] On Behalf Of Jorey Bump
Sent: Wednesday, September 14, 2005 4:37 PM
To: mod_python at modpython.org
Subject: Re: [mod_python] PythonImport: Can someone please draw a diagramfor
this idiot?
Jorey Bump wrote:
> jamestmcneill-python at yahoo.co.uk wrote:
>
>> 3) From this I can see that the PythonImport directive doesn't seem
>> to be working at all (or at least, in any way I expected it to). It
>> does not produce a compiled version of the module specified,
>
> This is not unusual. The user that apache runs as must have write
> permissions in the directory in order to produce a .pyc file. I'm not
> sure what happens under Windows regarding this, but if I want a
> compiled version of the module under Linux, I compile it ahead of time
> or change the permissions (rarely).
Having said that, I just tried using the PythonImport statement, and I also
see no evidence that it works. I may be using or testing it incorrectly,
however.
_______________________________________________
Mod_python mailing list
Mod_python at modpython.org
http://mailman.modpython.org/mailman/listinfo/mod_python
|