Python 从 PIL 导入图像 - 导入错误:没有名为 PIL 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26599757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:44:13  来源:igfitidea点击:

from PIL import Image - ImportError: No module named PIL

pythonmacosmodulepython-imaging-librarypillow

提问by swanb034

I know there are a number of questions already on stackoverflow related to this issue and I have read them all, but still I am having no success with this issue. I am hoping somebody can help me out with this.

我知道在 stackoverflow 上已经有很多与这个问题相关的问题,我已经阅读了所有问题,但我仍然没有解决这个问题。我希望有人能帮我解决这个问题。

I have installed and reinstalled Pillow 10 times now. I have updated my .bash_profile. Still, I get the same error message.

我现在已经安装并重新安装了 Pillow 10 次。我已经更新了我的 .bash_profile。尽管如此,我还是收到了相同的错误消息。

This is my .bash_profile:

这是我的 .bash_profile:

export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH="$PATH:/usr/local/bin/"
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"

This is my code:

这是我的代码:

import sys
import string
import re
from PIL import Image

It chokes on the 4th line every time with the message: ImportError: No module named PIL. I have also tried replacing the fourth line with

它每次都在第 4 行出现消息:ImportError: No module named PIL。我也试过用

import Image

also with no success. I know there are many questions similar to this one on here but believe me I have been reading the answers on those with no success so I'm hoping somebody here can help me with my particular situation. Thanks!

也没有成功。我知道这里有很多与这个问题类似的问题,但相信我,我一直在阅读那些没有成功的问题的答案,所以我希望这里有人可以帮助我解决我的特殊情况。谢谢!

采纳答案by blearn

I was experiencing a similar issue. Fixed it by pip installing WITHOUT sudo.

我遇到了类似的问题。通过 pip 安装而无需 sudo 修复它。

pip install pillow

instead of

代替

sudo pip install pillow

回答by Subbiah Thannirmalai

I encountered this while installing tensorflow code on NVIDIA Jetson Nano. This works for me:

我在 NVIDIA Jetson Nano 上安装 tensorflow 代码时遇到了这个问题。这对我有用:

    pip3 install Image