【问题标题】:Python PIL import Mac compatiblityPython PIL 导入 Mac 兼容性
【发布时间】:2014-12-24 15:56:35
【问题描述】:
我想了很久,我可以重定向 python 导入。
所以在我的机器上我做了:
pip install pil
然后我可以这样做:
from PIL import Image
这很好用,但问题是许多程序只想要图像,他们想要:
import Image
现在我的问题是我可以“重定向”上述语句以便我可以使用 import Image 吗?
如果这不起作用,我怎样才能使它起作用?
【问题讨论】:
标签:
python
image
macos
python-imaging-library
【解决方案1】:
基本上你可以使用here提到的任何方法。
在我的 linux 安装中,PIL 已经使用其中一个 - 有一个名为 PILcompat 的目录,其中包含 Image.py 等文件,还有一个名为 PILcompat.pth 的文件,用于告诉 python 将此目录添加到其模块搜索路径.
这样当
import Image
被执行,python 找到执行其内容的 PILcompat/Image.py -
from PIL.Image import *
我猜你的机器上缺少 .pth 文件或目录。