Python PIL没有属性'Image' [英] Python PIL has no attribute 'Image'

查看:3020
本文介绍了Python PIL没有属性'Image'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python2.6并且今天早上遇到了问题。它说模块没有属性图像。这是我的意见。为什么我第一次不能使用PIL.Image?

I'm using python2.6 and got a problem this morning. It said 'module' has no attribute 'Image'. Here is my input. Why the first time I can not use PIL.Image?

>>> import PIL
>>> PIL.Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Image'
>>> from PIL import Image
>>> Image
<module 'PIL.Image' from '/usr/lib/python2.6/dist-packages/PIL/Image.pyc'>
>>> PIL.Image
<module 'PIL.Image' from '/usr/lib/python2.6/dist-packages/PIL/Image.pyc'>


推荐答案

PIL的 __ init __。py 只是一个常见的空存根。它本身不会神奇地导入任何东西。

PIL's __init__.py is just an empty stub as is common. It won't magically import anything by itself.

当您从PIL导入图像执行时,它会在PIL中查找打包并找到文件Image.py并导入它。当您执行 PIL.Image 时,您实际上是在PIL模块上进行属性查找(除非您明确导入内容,否则它只是一个空存根)。

When you do from PIL import Image it looks in the PIL package and finds the file Image.py and imports that. When you do PIL.Image you are actually doing an attribute lookup on the PIL module (which is just an empty stub unless you explicitly import stuff).

实际上,导入模块通常不会导入子模块。 os.path 是一个着名的例外,因为os模块很神奇。

In fact, importing a module usually doesn't import submodules. os.path is a famous exception, since the os module is magic.

更多信息:

图像模块

这篇关于Python PIL没有属性'Image'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆