macos - ImportError : no module named Image, ImportError : no module named PIL -- Python, Anaconda,PIL, Pillow ,mac 10.10.3,

标签 macos python-2.7 python-imaging-library anaconda pillow

我正在使用 Mac OS x 10.10.3 Yosemite 和 Python 2.7.9 |Anaconda 2.2.0 (x86_64) 来处理很多 python 的东西。我正在使用 Eclipse 和谷歌应用引擎。

我用完了堆栈溢出帖子来阅读很多人都遇到的这个错误,然后通过某种对我不起作用的方式解决。

我收到此错误:

导入图片
ImportError:没有名为 Image 的模块

从此代码:

try:
    from PIL import Image
except:
    import Image

在我已经尝试过以下操作之后:
conda install pillow
sudo pip install pillow
pip install pillow
pip install pil

一些堆栈溢出帖子建议查看其他用户的路径是否存在,所以我在终端中尝试了这个:
python
Python 2.7.9 |Anaconda 2.2.0 (x86_64)| (default, Dec 15 2014, 10:37:34) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import sys
>>> print(sys.path)

得到:
['', 
'/Users/jrussek/anaconda/lib/python27.zip',
'/Users/jrussek/anaconda/lib/python2.7',
'/Users/jrussek/anaconda/lib/python2.7/plat-darwin', 
'/Users/jrussek/anaconda/lib/python2.7/plat-mac', 
'/Users/jrussek/anaconda/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/jrussek/anaconda/lib/python2.7/lib-tk',
'/Users/jrussek/anaconda/lib/python2.7/lib-old',
'/Users/jrussek/anaconda/lib/python2.7/lib-dynload',
'/Users/jrussek/anaconda/lib/python2.7/site-packages',
'/Users/jrussek/anaconda/lib/python2.7/site-packages/Sphinx-1.2.3 py2.7.egg', 
'/Users/jrussek/anaconda/lib/python2.7/site-packages/aeosa', 
'/Users/jrussek/anaconda/lib/python2.7/site-packages/cryptography-0.8-py2.7-macosx-10.5-x86_64.egg', 
'/Users/jrussek/anaconda/lib/python2.7/site-packages/setuptools-14.3-py2.7.egg']

我认为它不在我的路径中,所以我尝试附加该东西:
 PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL

看起来没有出现。

所以我尝试了 10 种不同的方式卸载和重新安装。我只为 Pillow 而不是 PIL 这样做,因为我为 PIL 尝试了不同的东西,并查看了很多说使用 Pillow 而不是 PIL 的帖子,因为 PIL 已被弃用。

无论如何,对于 Pillow ,我不断得到:
Requirement already up-to-date: pillow in ./anaconda/lib/python2.7/site-packages

显然 Pillow 已经安装在anaconda中,但这无助于我不断收到的导入错误。

所以然后我尝试了 conda install Pillow ,

它升级了一些东西:

但是..我尝试再次运行我的代码,但无论我尝试什么导入语句,我仍然没有找到任何模块。

建议?请?任何人?

最佳答案

首先,尝试使用(大写字母 P)安装 Pillow

pip install Pillow

然后使用
从 PIL 导入图像
“Pillow 是 Python Imaging Library PIL 的一个分支,不再维护。但是,为了保持向后兼容性,使用了旧的模块名称。”发件人:pillow installed, but "no module named pillow" - python2.7 - Windows 7 - python -m install pillow

关于macos - ImportError : no module named Image, ImportError : no module named PIL -- Python, Anaconda,PIL, Pillow ,mac 10.10.3,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31016085/

相关文章:

multithreading - Python 多处理队列慢

python - 使用 PIL 将 PNG32 转换为 PNG8,同时保留透明度

macos - Mac 测试场景

objective-c - 非 Cocoa 命令行应用程序是否与 Mac App Store 兼容?

linux - 使用 Readline 在 bash 中注释掉命令行

python - 通过cmd窗口在Python中打开图像

python-3.x - 错误: name 'Image' not defined

Ruby 2.1 和 Nokogiri 安装错误?

Python 类实例 __dict__ 不包含所有实例变量。为什么?

python - 对 numpy 数组的每一行的唯一列索引进行采样