要使用图像,我执行了以下操作:
pip install pil
from PIL import Image
但是很多程序只想要图像:
import Image
我该如何使用
import Image
?
基本上您可以使用这里提到的任何方法。
在我的 Linux 安装中,PIL 已经使用了其中之一 - 有一个名为 PILcompat 的目录,其中包含 Image.py 等文件,以及一个名为 PILcompat.pth 的文件,用于告诉 python 将此目录添加到其模块搜索路径中。 这样当
import Image
执行后,python找到PILcompat/Image.py执行其内容-
from PIL.Image import *
我猜测您的计算机上缺少 .pth 文件或目录。