[mod_python] PythonImport failure

Gregory (Grisha) Trubetskoy grisha at verio.net
Tue Mar 27 16:00:45 EST 2001


Try the mod_python 2.7.2 DLL and see if the problems persist

Grisha

On Tue, 27 Mar 2001, Chris Hagner wrote:

> A specific question about why PythonImport works for some modules and not
> for others.
>
> 1.  The following statement works.  It compiles/imports apache.py at server
> startup.
>
> PythonImport mod_python.apache
>
> 2.  Now, when I create a dummy module in mod_python/MyObject.py
>
> def myFunction():
>     return "MyObject.myFunction()"
>
> class MyObject:
>
>     def __init__(self):
>         pass
>
> The following statement does not work.
>
> PythonImport mod_pytnon.MyObject
>
> Here's the error in error.log
> [Tue Mar 27 13:07:56 2001] [error] directive_PythonImport: error import
> mod_python.MyObject
> TypeError: must assign list (not "string") to slice
>
> Any help on this error msg?
>
> BTW, the first error line appears at start up... second appears upon
> immediate shutdown... probably just a buffer thing, but I thought I'd share.
>
> 3.  I also tried import a base module which worked fine.
>
> PythonImport string
>
> 4.  But when I created a copy of string.py and simply renamed it, it didn't
> work.
>
> PythonImport copyofstring
>
> Any thoughts on why mod_python appears to like some modules and not others?
>
> Thanks in advance.
>
> Chris
>
>
>
> -----Original Message-----
> From: Chris Hagner [mailto:CHagner at fool.com]
> Sent: Thursday, March 15, 2001 12:07 PM
> To: 'Gregory (Grisha) Trubetskoy'
> Cc: 'mod_python at modpython.org'
> Subject: RE: [mod_python] PythonImport failure
>
>
> Thanks for the response.  For my tests, mypackage is a package named
> 'toolkit' and the mymodule is a module named 'brandconfig'.
>
> Oh yeah, I'm doing this on Apache/1.3.19 (Win32) mod_python/2.7.1
> Python/2.0.  I'm on Win2K (for development, sigh).
>
> INTERACTIVE SESSION TEST:
> ******************************
>
> Here's my python interactive session... the module only contains a single
> variable x.
>
> >>> import toolkit.brandconfig
> >>> dir(toolkit.brandconfig)
> ['__builtins__', '__doc__', '__file__', '__name__', 'x']
> >>> toolkit.brandconfig.x
> 123
> >>>
>
> So, the module is importable in my python environment.
>
>
> APACHE PYTHONIMPORT TEST:
> ******************************
>
> Just to be sure, I ran the apache test again.  Here's the httpd.conf entry.
> Nothing shocking.
>
> <Directory "D:/site/brand1/htdocs">
>    AddHandler python-program .py
>    PythonHandler toolkit.publisher
>    PythonDebug on
>    PythonImport toolkit.brandconfig
> </Directory>
>
> Here's the response in the log upon starting apache.
>
>    [Thu Mar 15 11:39:10 2001] [error] directive_PythonImport: error
> importing toolkit.brandconfig
>
> Same as before.  Now, just to be sure, I blew away the brandconfig.py file
> (and the .pyc) so that it shouldn't even find it (just to see if I could get
> a different error if it didn't even exist).  Result: No change.  Same error
> in error.log.  Apparently, it's not even finding it.
>
> APACHE PYTHON SCRIPT TEST:
> ******************************
>
> So, it wasn't importing it on start up.  How about a python script in
> mod_python?
>
> Here's the code blurb...
>
> 	import foolkit.brandconfig
>        out_string = "foolkit.brandconfig.x: %s \n"% foolkit.brandconfig.x
>
> Did it work?  yup, the page displayed
>
> 	foolkit.brandconfig.x: 123
>
>
>
> Yes, I have read through the documentation and my need is to initialize a
> number of objects (i.e. dbconn pool) for use throughout my applications.
> Now, I am using a custom handler, so I could simply have the handler do this
> initialization the first time it runs, but the PythonImport appeared to be a
> code-free way to achieve this goal.  Do you all think this is a case where I
> *really* need it?  If not, could someone share an example of when it really
> deserves to be used?
>
> Thanks again for the help.
>
> Chris
>
> -----Original Message-----
> From: Gregory (Grisha) Trubetskoy [mailto:grisha at verio.net]
> Sent: Thursday, March 15, 2001 11:26 AM
> To: Chris Hagner
> Cc: 'mod_python at modpython.org'
> Subject: Re: [mod_python] PythonImport failure
>
>
>
> Chris -
>
> Have you tried
>
> >>> import mypackage.mymodule
>
> from an interactive Python session?
>
> Also, regarding PythonPath - if you read documentation carefully, you'll
> notice that it says that no other directives have any effect at the time
> PythonImport is executed.
>
> Generally, you should not use PythonImport unless you *really* need it,
> which is almost never the case.
>
> Grisha
>
>
> On Thu, 15 Mar 2001, Chris Hagner wrote:
>
> > Greetings,
> >
> > I'm trying to get the PythonImport command to work.  Been through the
> > documentation, but it appears to want more than simply inserting
> >
> >    PythonImport mypackage.mymodule
> >
> > within my Directory tags in httd.conf.
> >
> > While mypackage.mymodule is under the standard python lib directory
> > (therefore should be found through the sys.path), the system spat out the
> > following...
> >
> >     ...[error] directive_PythonImport: error importing mypackage.mymodule
> >
> > I then moved the module to a different directory and appended that
> directory
> > to the sys.path using the PythonPath command (just to see if that allowed
> it
> > to find the module).  No luck.
> >
> > I've found a handful of posts from June and August of last year, but no
> > posted solutions to getting the PythonImport command to work correctly.
> Of
> > course, there's a CVS commit with the comment "PythonImport works now" so
> > I'm pretty sure it's me...
> >
> > As a random test, I tried a standard module...
> >
> >    PythonImport sys
> >
> > which appeared to work (no error msg), but I'm not really confident that
> > this was a meaningful test.
> >
> > Thanks in advance.
> >
> > Chris
> > chagner _at_ fool _dot_ com
> >
> >
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://www.modpython.org/mailman/listinfo/mod_python
> >
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
>




More information about the Mod_python mailing list