我可以重定向 python 导入吗? 所以在我的机器上我做了:
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 文件或目录。