【问题标题】:Package (Python PIL/Pillow) installed but I can't import it已安装包(Python PIL/Pillow)但我无法导入它
【发布时间】:2015-08-13 09:40:56
【问题描述】:

我想做一些图像处理,但遇到了问题。导入枕头模块似乎不起作用。我在这里找到了一个简单的脚本来检查安装了哪些包,我找到了,但是导入它似乎不起作用。

这是我要运行的代码:

import pip

installed_packages = pip.get_installed_distributions()
installed_pillow_packages = [
    "%s==%s" % (i.key, i.version)
    for i in installed_packages
    if "pil" in i.key.lower()
]
print(installed_pillow_packages)

import pillow

结果如下:

runfile('C:/Users/Augustas/.spyder2/temp.py', wdir=r'C:/Users/Augustas/.spyder2')
['pillow==2.6.1']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 601, in runfile
    execfile(filename, namespace)
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 66, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "C:/Users/Augustas/.spyder2/temp.py", line 7, in <module>
    import pillow
ImportError: No module named pillow

我正在使用 Spyder 和 Python 2.7.9 在 Windows 8.1 上运行它。

【问题讨论】:

    标签: python pip package python-imaging-library


    【解决方案1】:

    您导入不正确。尝试使用:

    import PIL
    

    from PIL import Image
    

    PIL,即不再维护 Python Imaging Library,改用Pillow。为了保持向后兼容性,PIL 模块名称用于导入。

    【讨论】:

      【解决方案2】:

      其实Pillow是安装在名字“PIL”下的,所以:

      import PIL as pillow
      from PIL import Image
      ...
      

      看这个:

      【讨论】:

        【解决方案3】:

        查看文档:

        http://pillow.readthedocs.org/handbook/tutorial.html

        你必须像这样导入它:

        import PIL
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-06-14
          • 2023-01-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-12-02
          • 2021-03-30
          • 1970-01-01
          相关资源
          最近更新 更多