[英]Pillow is installed, but still getting “ImportError: No module named PIL”
I did find this question asked by few more people, but none of those exactly met my situation, so asking here myself.我确实发现有更多人问了这个问题,但没有一个完全符合我的情况,所以我自己在这里问。 I've (rather had) two versions of Python (2.7 and 3.4.3) on my Mac running the latest MacOS High Sierra.
我在运行最新 MacOS High Sierra 的 Mac 上有(而是有)两个版本的 Python(2.7 和 3.4.3)。 As I understand, the v2.7 comes as default installation with the MacOS.
据我了解,v2.7 是 MacOS 的默认安装。 And I installed the 3.4.3 (from .dmg file downloaded from the python site).
我安装了 3.4.3(来自从 python 站点下载的 .dmg 文件)。 Thus now, the python command defaults to the 2.7, while python3 points to the 3.4.3 in the terminal.
因此现在,python 命令默认为 2.7,而 python3 指向终端中的 3.4.3。 While trying to learn, I tried a python script that uses
在尝试学习时,我尝试了一个使用
import PIL
and from PIL import Image
import PIL
和from PIL import Image
But when running, this gave the error ImportError: No module named PIL
.但是在运行时,这给出了错误
ImportError: No module named PIL
。 Upon research on google, I figured out to install PIL and Pillow using经过对谷歌的研究,我发现使用以下方法安装 PIL 和 Pillow
sudo pip install Pillow
It installed correctly, but I'm still getting the same error.它安装正确,但我仍然遇到相同的错误。 To remove the confusion, I decided to remove the python 3.4.3 from the system.
为了消除混乱,我决定从系统中删除 python 3.4.3。 But even after it's removed, I still get the same error.
但即使将其删除,我仍然遇到相同的错误。 Even
pip list
displays Pillow 5.1.0
alright.即使
pip list
显示Pillow 5.1.0
不错。 So right now, I've only Python 2.7, and the error persists, while Pillow is also in there.所以现在,我只有 Python 2.7,错误仍然存在,而 Pillow 也在那里。
which python
gives /opt/local/bin/python
as the path. which python
将/opt/local/bin/python
作为路径。
Does any of the above ring a bell?以上任何一项都敲响了警钟吗? Any ideas, what else could be missing here?
任何想法,这里还缺少什么?
Phew, finally found the issue.噗,终于找到问题了。 Thanks @Yash for the pointers.
感谢@Yash 的指点。 Incidentally I did a
which -a python
and surprisingly got this output:顺便说一句,我做了一个
which -a python
并令人惊讶地得到了这个输出:
/opt/local/bin/python
/usr/bin/python
Damn, I don't remember when I installed a second 2.7 version on the /opt/local/bin
folder (probably via macports).该死,我不记得我什么时候在
/opt/local/bin
文件夹(可能通过 macports)安装了第二个 2.7 版本。 Alright, removed the confusion, deleted this python, so now I'm left only with the system installed python at /usr/bin
.好吧,消除混乱,删除这个python,所以现在我只剩下系统安装的python在
/usr/bin
。 And now the imports all run perfectly fine as expected.现在进口都按预期运行得很好。 :-)
:-)
Try this,试试这个,
sudo pip install image
I hope it works!我希望它有效! One more thing, do check if you're running python3 filename.py instead of python filename.py, if you want to install it for Python 3, run the command,
还有一件事,请检查您是否正在运行 python3 filename.py 而不是 python filename.py,如果您想为 Python 3 安装它,请运行命令,
sudo pip3 install Pillow
Basic Installation:基本安装:
pip install Pillow
Windows Installation:视窗安装:
pip install Pillow
Reference: https://pillow.readthedocs.io/en/stable/installation.html参考: https : //pillow.readthedocs.io/en/stable/installation.html
Try this.试试这个。 It worked for me
它对我有用
pip install --upgrade --force-reinstall pillow
If you get something like access denied error run the below command如果您收到类似拒绝访问错误的信息,请运行以下命令
pip install --upgrade --force-reinstall pillow --user
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.