简体   繁体   English

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

[英]How do I uninstall PIL for python 2.7 and use Pillow instead?

I have been searching for hours and can't find anything so I thought I'd ask here.我一直在寻找几个小时,但找不到任何东西,所以我想我会在这里问。

So my issue is with PIL and Pillow.所以我的问题是 PIL 和 Pillow。 I need to use python 2.7 as I'm using SimpleCV which isn't supported in Python 3 yet.我需要使用 python 2.7,因为我使用的是 Python 3 尚不支持的 SimpleCV。

When I try to uninstall PIL using sudo pip uninstall PIL it outputs: Cannot uninstall requirement PIL, not installed .当我尝试使用sudo pip uninstall PIL时,它输出: Cannot uninstall requirement PIL, not installed

This works for python 3 and allows me to use Pillow using from PIL import Image .这适用于 python 3 并允许我使用from PIL import Image使用 Pillow。 If I try to use import Image I get an error because it doesn't exist however, for python 2.7 (the version I need to use), both from PIL import Image and import Image work making me believe PIL hasn't been uninstalled from python 2.7.如果我尝试使用import Image我会收到一个错误,因为它不存在,但是对于 python 2.7(我需要使用的版本), from PIL import Imageimport Image的工作让我相信 PIL 没有被卸载python 2.7。

Am I correct in thinking that it hasn't been uninstalled for python 2.7?我认为它没有为 python 2.7 卸载是正确的吗? If so how do I uninstall it?如果是这样我该如何卸载它? Or is it something else?或者是别的什么?

Thanks in advance!提前致谢!

PS: Just in case it matters, I'm using a Raspberry Pi. PS:以防万一,我使用的是 Raspberry Pi。

I suspect you have successfully uninstalled PIL, and that you in fact have Pillow installed.我怀疑您已经成功卸载了 PIL,并且您实际上已经安装了 Pillow。 Pillow is installed under the package name PIL. Pillow 安装在包名 PIL 下。 This allows you to swap out Pillow with PIL without having to rewrite any of your code.这允许您用 PIL 替换 Pillow,而无需重写任何代码。 Pillow is "just" a PIL fork. Pillow“只是”一个PIL叉子。

You can check if import PIL actually loads Pillow by doing:您可以通过执行以下操作来检查import PIL实际加载 Pillow:

import PIL
print PIL.PILLOW_VERSION

If you have Pillow installed it should output some version.如果你安装了 Pillow,它应该输出一些版本。 It says 3.3.1 here, but I am using Python3.它在这里说 3.3.1,但我使用的是 Python3。 If you do not have Pillow, but PIL, it should result in an error.如果你没有 Pillow,而是 PIL,它应该会导致错误。

Update : You may now see a warning like :更新:您现在可能会看到如下警告:

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

In that case , try running :在这种情况下,请尝试运行:

print(__PIL.__version__)

Thanks for all this.感谢这一切。

I still have OSX 10.13.6 High Sierra.我还有 OSX 10.13.6 High Sierra。 Not sure if this was part of my problem or if the above is only for Windows, although I have used pip on my Mac?不确定这是否是我的问题的一部分,或者以上是否仅适用于 Windows,尽管我在我的 Mac 上使用过 pip?

I had to do the following:我必须执行以下操作:

brew upgrade # this took about half an hour brew upgrade # 这花了大约半个小时

brew install Pillow # this took over 2 hours (not sure how long it actually took, but I went to sleep late last night after watching the install for a while). brew install Pillow # 这花了 2 个多小时(不确定实际花了多长时间,但我看了一会儿安装后昨晚睡得很晚)。

There were some errors and I had to:有一些错误,我不得不:

rm /usr/local/bin/2to3 brew link --overwrite python@3.9 rm /usr/local/bin/2to3 brew link --overwrite python@3.9

I've also just linked python to python3.9 so that I don't have to keep typing python3 <filename.py>, ie:我还刚刚将 python 链接到 python3.9,这样我就不必继续输入 python3 <filename.py>,即:

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

allows me to type python <filename.py>允许我输入 python <filename.py>

Then close and reopen the terminal for these changes to be effected, and I was in VS Code when I did the brew install, so I had to close and reopen VS Code as well.然后关闭并重新打开终端以使这些更改生效,当我执行 brew install 时我在 VS Code 中,所以我也必须关闭并重新打开 VS Code。

See https://itsmycode.com/python-importerror-no-module-named-pil-solution/请参见https://itsmycode.com/python-importerror-no-module-named-pil-solution/

Note that "pip uninstall PIL" failed on my Mac, so I assume it wasn't installed the first place, but I did already have HomeBrew installed.请注意,“pip uninstall PIL”在我的 Mac 上失败,所以我假设它没有安装在第一位,但我确实已经安装了 HomeBrew。

https://pillow.readthedocs.io/en/stable/installation.html https://pillow.readthedocs.io/en/stable/installation.html

https://brew.sh/ https://brew.sh/

Note that after doing this whole install I had to reinstall Django, ie请注意,完成整个安装后,我必须重新安装 Django,即

pip3 install Django pip3 安装 Django

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM