python - 如何为 python 2.7 卸载 PIL 并改用 Pillow?

标签 python python-2.7 pip python-imaging-library

我已经搜索了几个小时,但找不到任何东西,所以我想在这里问一下。

所以我的问题是 PIL 和 Pillow。我需要使用 python 2.7,因为我使用的是 Python 3 尚不支持的 SimpleCV。

当我尝试使用 sudo pip uninstall PIL 卸载 PIL 时,它输出:Cannot uninstall requirement PIL, not installed

这适用于 python 3,并允许我使用 from PIL import Image 使用 Pillow。如果我尝试使用 import Image 我会得到一个错误,因为它不存在但是,对于 python 2.7(我需要使用的版本),from PIL import Imageimport Image 的工作让我相信 PIL 还没有从 python 2.7 中卸载。

我认为它没有为 python 2.7 卸载是正确的吗?如果是这样我该如何卸载它?还是其他原因?

提前致谢!

PS:以防万一,我使用的是 Raspberry Pi。

最佳答案

我怀疑您已经成功卸载了 PIL,并且您实际上已经安装了 Pillow。 Pillow 安装在包名 PIL 下。这允许您用 PIL 替换 Pillow,而无需重写任何代码。 Pillow “只是”一个 PIL fork 。

您可以检查是否 import PIL实际上通过执行加载 Pillow:

import PIL
print PIL.PILLOW_VERSION

如果你安装了 Pillow,它应该输出一些版本。这里说的是 3.3.1,但我用的是 Python3。如果您没有 Pillow,而是 PIL,它应该会导致错误。

更新: 您现在可能会看到如下警告:

<stdin>:1: DeprecationWarning: PILLOW_VERSION is deprecated and will be removed in a future release. Use __version__ instead.

在那种情况下,尝试运行:

print(__PIL.__version__)

关于python - 如何为 python 2.7 卸载 PIL 并改用 Pillow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40809943/

相关文章:

python - 迭代Python列表的列表并删除每个子列表的最终索引,无需导入

javascript - GAE - 区分具有相同 ip 的多个客户端

python - Matplotlib Figuresize 被 rcParams 忽略

python - 根据行内容分配变量

python - 清理模板代码

python - 按下按钮时执行功能

python:子进程在使用 sudo 时给我不同的结果

python-3.x - 如何在 setup.py 中指定递归依赖?

python - 为什么 Travis CI 无法构建 Python 项目?

package - pip 安装到 deb 二进制文件