我在 shell 中使用这个命令来安装 PIL:
easy_install PIL
然后我运行
python
并输入: import PIL
。但我收到此错误:Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named PIL
我从来没有遇到过这样的问题,你怎么看?
最佳答案
在某些 PIL 安装中,您必须执行
import Image
而不是 import PIL
(PIL 实际上并不总是以这种方式导入)。由于 import Image
对您有用,这意味着您实际上已经安装了 PIL。为库和 Python 模块使用不同的名称是不寻常的,但这是为(某些版本的)PIL 选择的名称。
您可以从 official tutorial 获取有关如何使用此模块的更多信息。
PS :实际上,在某些安装中,
import PIL
确实有效,这增加了困惑。 @JanneKarila 发现的 example from the documentation 以及一些更新版本的 MacPorts PIL 包 (1.1.7) 也证实了这一点。关于python - 导入错误 : No module named PIL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8863917/