Macos ImportError:没有名为Image的模块,ImportError:没有名为PIL的模块--Python、Anaconda、PIL、pillow、mac 10.10.3、,

Macos ImportError:没有名为Image的模块,ImportError:没有名为PIL的模块--Python、Anaconda、PIL、pillow、mac 10.10.3、,,macos,python-2.7,python-imaging-library,anaconda,pillow,Macos,Python 2.7,Python Imaging Library,Anaconda,Pillow,我使用MacOSX10.10.3Yosemite和Python2.7.9 | Anaconda2.2.0(x86_64)来编写许多Python内容。我正在使用eclipse和google应用程序引擎 我的堆栈溢出帖子已经没有了,很多人都会读到这个错误,然后用一些对我不起作用的方法来解决 我得到了这个错误: 导入图像 ImportError:没有名为Image的模块 来自此代码: try: from PIL import Image except: import Image 在

我使用MacOSX10.10.3Yosemite和Python2.7.9 | Anaconda2.2.0(x86_64)来编写许多Python内容。我正在使用eclipse和google应用程序引擎

我的堆栈溢出帖子已经没有了,很多人都会读到这个错误,然后用一些对我不起作用的方法来解决

我得到了这个错误:

导入图像 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种不同的方式卸载和重新安装。我只为枕头做了这件事,而不是PIL,因为我尝试了不同的PIL方法,并查看了很多帖子,上面说使用枕头,而不是PIL,因为PIL不受欢迎

无论如何,对于枕头,我一直得到:

Requirement already up-to-date: pillow in ./anaconda/lib/python2.7/site-packages
很明显,pillow已经安装在anaconda中,但这无助于我不断遇到的导入错误

然后我试着装了个枕头

它升级了一些东西:

但是。。我尝试再次运行我的代码,但无论我尝试使用什么import语句,仍然找不到任何模块


建议?请有人吗?

以下几点对我很有用:

from PIL import Image
这是行不通的:

import Image
枕头套装

$ conda search pillow
Fetching package metadata: ....
pillow                       2.1.0                    py33_0  defaults        
                             2.1.0                    py27_0  defaults        
                             2.1.0                    py26_0  defaults        
                             2.3.1                    py34_0  defaults        
                             2.3.1                    py33_0  defaults        
                             2.3.1                    py27_0  defaults        
                             2.3.1                    py26_0  defaults        
                             2.4.0                    py34_0  defaults        
                             2.4.0                    py33_0  defaults        
                             2.4.0                    py27_0  defaults        
                             2.4.0                    py26_0  defaults        
                          .  2.5.1                    py34_0  defaults        
                             2.5.1                    py33_0  defaults        
                             2.5.1                    py27_0  defaults        
                             2.5.1                    py26_0  defaults        
                             2.7.0                    py34_0  defaults        
                             2.7.0                    py33_0  defaults        
                             2.7.0                    py27_0  defaults        
                             2.7.0                    py26_0  defaults        
                             2.7.0                    py34_1  defaults        
                             2.7.0                    py33_1  defaults        
                             2.7.0                    py27_1  defaults        
                             2.7.0                    py26_1  defaults        
                             2.8.1                    py34_1  defaults        
                             2.8.1                    py33_1  defaults        
                             2.8.1                    py27_1  defaults        
                             2.8.1                    py26_1  defaults        
                             2.8.1                    py34_2  defaults        
                             2.8.1                    py33_2  defaults        
                             2.8.1                    py27_2  defaults        
                             2.8.1                    py26_2  defaults        
                             2.8.2                    py34_0  defaults        
                             2.8.2                    py33_0  defaults        
                             2.8.2                    py27_0  defaults        
                             2.8.2                    py26_0  defaults        
                          *  2.9.0                    py34_0  defaults        
                             2.9.0                    py33_0  defaults        
                             2.9.0                    py27_0  defaults        
                             2.9.0                    py26_0  defaults  
Python路径

$ python
Python 3.4.3 |Anaconda 2.1.0 (x86_64)| (default, Mar  6 2015, 12:07:41) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print (sys.path)
['', '/Users/erwin/anaconda/lib/python34.zip', '/Users/erwin/anaconda/lib/python3.4', '/Users/erwin/anaconda/lib/python3.4/plat-darwin', '/Users/erwin/anaconda/lib/python3.4/lib-dynload', '/Users/erwin/anaconda/lib/python3.4/site-packages', '/Users/erwin/anaconda/lib/python3.4/site-packages/Sphinx-1.3.1-py3.4.egg', '/Users/erwin/anaconda/lib/python3.4/site-packages/setuptools-18.1-py3.4.egg']
图像使用情况

$ conda search pillow
Fetching package metadata: ....
pillow                       2.1.0                    py33_0  defaults        
                             2.1.0                    py27_0  defaults        
                             2.1.0                    py26_0  defaults        
                             2.3.1                    py34_0  defaults        
                             2.3.1                    py33_0  defaults        
                             2.3.1                    py27_0  defaults        
                             2.3.1                    py26_0  defaults        
                             2.4.0                    py34_0  defaults        
                             2.4.0                    py33_0  defaults        
                             2.4.0                    py27_0  defaults        
                             2.4.0                    py26_0  defaults        
                          .  2.5.1                    py34_0  defaults        
                             2.5.1                    py33_0  defaults        
                             2.5.1                    py27_0  defaults        
                             2.5.1                    py26_0  defaults        
                             2.7.0                    py34_0  defaults        
                             2.7.0                    py33_0  defaults        
                             2.7.0                    py27_0  defaults        
                             2.7.0                    py26_0  defaults        
                             2.7.0                    py34_1  defaults        
                             2.7.0                    py33_1  defaults        
                             2.7.0                    py27_1  defaults        
                             2.7.0                    py26_1  defaults        
                             2.8.1                    py34_1  defaults        
                             2.8.1                    py33_1  defaults        
                             2.8.1                    py27_1  defaults        
                             2.8.1                    py26_1  defaults        
                             2.8.1                    py34_2  defaults        
                             2.8.1                    py33_2  defaults        
                             2.8.1                    py27_2  defaults        
                             2.8.1                    py26_2  defaults        
                             2.8.2                    py34_0  defaults        
                             2.8.2                    py33_0  defaults        
                             2.8.2                    py27_0  defaults        
                             2.8.2                    py26_0  defaults        
                          *  2.9.0                    py34_0  defaults        
                             2.9.0                    py33_0  defaults        
                             2.9.0                    py27_0  defaults        
                             2.9.0                    py26_0  defaults  
这在我的终端和EclipsePydevNow中都有效

>>> from PIL import Image
>>> a = Image.new("RGB", (512,512), "red")
>>> a.show()

首先,试着用(大写字母p)安装枕头

然后使用 从PIL导入图像
“Pillow是PIL的一个分支,即不再维护的Python映像库。但是,为了保持向后兼容性,使用了旧的模块名。”From:

我与您处于相同的位置至少有几次,我设法通过其他解决方案解决了它。然后它又坏了。下面是我为修复它所做的:

打开两个查找窗口

在其中一个示例中,导航到:

//anaconda/pkgs/pillow-3.2.0-py27_0/lib/python2.7/site-packages
在此文件夹中,您将找到该文件夹

PIL
复制此文件夹并将其粘贴到可访问的位置

现在打开anaconda目录中的Python2.7环境文件夹。对我来说,这是:

//anaconda/envs/py27/lib/python2.7/site-packages
您只需更改其中的“py27”


即使其中已经有一个名为“PIL”的文件夹,也要将复制的PIL放在新的site packages文件夹中。据我所知,现有的PIL文件夹中有旧的或错误的,或东西。或者枕头安装不正确。我认为这相当于手动安装python模块。超级有趣

新版枕头已将“图像”的偏差更改为:


我遇到了与OP相同的问题:

  • macOS 10.12.5
  • 达尔文上的Python 2.7.13[GCC 4.2.1兼容苹果LLVM 8.1.0(clang-802.0.38)]
问题最终是我试图运行的.py文件

在脚本的顶部有一个:
#/usr/bin/python

但是,我的默认python不会从系统安装运行。我使用
homebrew
升级python,因此我的默认路径是:

$ which python
/usr/local/bin/python

我把顶部的shebang改成了
#/usr/local/bin/python
,之后我可以运行我的脚本(从PIL导入图像调用
)。

我使用了类似的堆栈,尽管我目前使用的是python 3.4。水蟒为我工作。当您键入
conda search pil
时,它对您说了什么?它说:
获取包元数据:。。。。pil 1.1.7 py27_0默认值诸如此类*2.8.2 py27_0默认值2.8.2 py26_0默认值
我对python 3.4.3-anaconda也有同样的问题分发:)帖子中的注意:我得到了这个错误:import Image ImportError:没有来自这个代码的名为Image的模块:try:From PIL import Image except:import Image——所以我认为代码应该尝试已经适合您的东西。。。还有什么建议吗?我没有更多的建议,但我可以向您展示我在工作配置中看到的内容。我将其添加到帖子中。此外,我从未在安装时尝试--upgrade选项,这可能一直是问题所在。(未经检验的理论)救了我的a。谢谢谢谢你发布这个!对于其他无法从scipy.misc import imread导入
的用户,卸载
pillow
并安装
pillow
修复了我的问题。
$ which python
/usr/local/bin/python