[mod_python] PythonImport failure

Chris Hagner CHagner at fool.com
Thu Mar 15 12:06:46 EST 2001


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
>



More information about the Mod_python mailing list