简体   繁体   中英

Python and Zope: Module will import in python but not in zope

I have installed the Image module http://www.pythonware.com/products/pil/ . I then try and import it in the python interpreter and successfully so:

>>> import Image
>>> 

But when I try to import the module in Zope via DTML page:

DTML page looks like:

<dtml-var import_image>

Which calls this script:

def import_image(self):
    import Image
    im = Image.open("/home/rv/Desktop/blah.jpg")
    return im

I then get this error:

"ImportError: No module named Image" How can there be no module when I can import it in the python interpreter?


EDIT

The python script is in Zopes extension folder

Try:

import PIL.Image

rather than:

import Image

Zope has an Image module and you could be encountering a namespace clash.

You can't just import any module in zope python script. Zope has some security restrictions. In your case you need create external method in %zope-instance%/Extensions

OR maybe your zope instance cannot find this library because it's running in another python environment. You should check if all parameters are right in %zope-instance%/bin/zopectl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM