如何为 python 2.7 卸载 PIL 并改用 Pillow?
How do I uninstall PIL for python 2.7 and use Pillow instead?
我已经搜索了几个小时,但找不到任何东西,所以我想在这里问一下。
所以我的问题是 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 Image
和 import Image
工作让我相信 PIL 还没有从 python 2.7.
中卸载
我认为它没有为 python 2.7 卸载是正确的吗?如果是这样我该如何卸载它?还是其他原因?
提前致谢!
PS:以防万一,我使用的是 Raspberry Pi。
我怀疑您已经成功卸载了 PIL,而且您实际上已经安装了 Pillow。 Pillow 安装在包名 PIL 下。这允许您用 PIL 替换 Pillow,而无需重写任何代码。枕头“只是”一个 PIL 叉子。
您可以检查 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__)
感谢这一切。
我还有 OSX 10.13.6 High Sierra。不确定这是否是我的问题的一部分,或者以上是否仅适用于 Windows,尽管我在我的 Mac?
上使用了 pip
我必须执行以下操作:
brew upgrade # this took about half an hour
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).
出现了一些错误,我不得不:
rm /usr/local/bin/2to3
brew link --overwrite python@3.9
我还刚刚将 python 链接到 python3.9,这样我就不必继续输入 python3 ,即:
ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
允许我输入 python
然后关闭并重新打开终端以使这些更改生效,而我在执行 brew install 时正在 VS Code 中,所以我也必须关闭并重新打开 VS Code。
见https://itsmycode.com/python-importerror-no-module-named-pil-solution/
请注意,“pip uninstall PIL”在我的 Mac 上失败,所以我假设它没有首先安装,但我确实已经安装了 HomeBrew。
https://pillow.readthedocs.io/en/stable/installation.html
请注意,完成整个安装后我必须重新安装 Django,即
pip3 install Django
我已经搜索了几个小时,但找不到任何东西,所以我想在这里问一下。
所以我的问题是 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 Image
和 import Image
工作让我相信 PIL 还没有从 python 2.7.
我认为它没有为 python 2.7 卸载是正确的吗?如果是这样我该如何卸载它?还是其他原因?
提前致谢!
PS:以防万一,我使用的是 Raspberry Pi。
我怀疑您已经成功卸载了 PIL,而且您实际上已经安装了 Pillow。 Pillow 安装在包名 PIL 下。这允许您用 PIL 替换 Pillow,而无需重写任何代码。枕头“只是”一个 PIL 叉子。
您可以检查 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__)
感谢这一切。
我还有 OSX 10.13.6 High Sierra。不确定这是否是我的问题的一部分,或者以上是否仅适用于 Windows,尽管我在我的 Mac?
上使用了 pip我必须执行以下操作:
brew upgrade # this took about half an hour
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).
出现了一些错误,我不得不:
rm /usr/local/bin/2to3 brew link --overwrite python@3.9
我还刚刚将 python 链接到 python3.9,这样我就不必继续输入 python3
ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
允许我输入 python
然后关闭并重新打开终端以使这些更改生效,而我在执行 brew install 时正在 VS Code 中,所以我也必须关闭并重新打开 VS Code。
见https://itsmycode.com/python-importerror-no-module-named-pil-solution/
请注意,“pip uninstall PIL”在我的 Mac 上失败,所以我假设它没有首先安装,但我确实已经安装了 HomeBrew。
https://pillow.readthedocs.io/en/stable/installation.html
请注意,完成整个安装后我必须重新安装 Django,即
pip3 install Django