无法在Windows上安装Pillow

20

安装过程要求 zlib,我甚至从 Github 上设置并克隆了它。我对这一切都很新奇。

错误信息:

C:\Users\GThell\Pillow>pip install -e .
Obtaining file:///C:/Users/GThell/Pillow
Requirement already satisfied: olefile in c:\users\gthell\appdata\local\programs\python\python36\lib\site-packages (from Pillow==3.5.0.dev0)
Installing collected packages: Pillow
  Running setup.py develop for Pillow
    Complete output from command c:\users\gthell\appdata\local\programs\python\python36\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\GThell\\Pillow\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps:
    Single threaded build for windows
    running develop
    running egg_info
    writing Pillow.egg-info\PKG-INFO
    writing dependency_links to Pillow.egg-info\dependency_links.txt
    writing requirements to Pillow.egg-info\requires.txt
    writing top-level names to Pillow.egg-info\top_level.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'Pillow.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no previously-included files found matching '.coveragerc'
    warning: no previously-included files found matching '.editorconfig'
    warning: no previously-included files found matching '.landscape.yaml'
    warning: no previously-included files found matching 'appveyor.yml'
    warning: no previously-included files found matching 'tox.ini'
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    writing manifest file 'Pillow.egg-info\SOURCES.txt'
    running build_ext


    The headers or library files could not be found for zlib,
    a required dependency when compiling Pillow from source.

    Please see the install instructions at:
       http://pillow.readthedocs.io/en/latest/installation.html

    Traceback (most recent call last):
      File "C:\Users\GThell\Pillow\setup.py", line 778, in <module>
        zip_safe=not debug_build(), )
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\site-packages\setuptools\command\develop.py", line 34, in run
        self.install_for_development()
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\site-packages\setuptools\command\develop.py", line 119, in install_for_development
        self.run_command('build_ext')
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\users\gthell\appdata\local\programs\python\python36\lib\distutils\command\build_ext.py", line 339, in run
        self.build_extensions()
      File "C:\Users\GThell\Pillow\setup.py", line 549, in build_extensions
        raise RequiredDependencyException(f)
    __main__.RequiredDependencyException: zlib

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\GThell\Pillow\setup.py", line 790, in <module>
        raise RequiredDependencyException(msg)
    __main__.RequiredDependencyException:

    The headers or library files could not be found for zlib,
    a required dependency when compiling Pillow from source.

    Please see the install instructions at:
       http://pillow.readthedocs.io/en/latest/installation.html

你可以使用Python的Anaconda发行版代替吗?我在安装通常很难安装的软件包时节省了很多时间。安装Anaconda后,只需执行conda install pillow即可完成!虽然不是必须的,但您可能需要先卸载当前版本的Python。 - pbreach
我对这些都很陌生。我正在自学Python,以便更多地了解深度学习/机器学习,并成为一名数据科学家。感谢您推荐Anaconda。 - GTHell
2
如果你能找到任何使用Linux而不是Windows来运行Python的方法,请尽量这样做。在Windows上安装和维护Python简直是一场噩梦。 - JonathanZ supports MonicaC
8个回答

11

使用:

easy_install pillow

pip 不知何故无法正常工作


8
我最近在Cygwin的Python3.6下安装了Pillow,并需要以下软件包:

  • gcc-core
  • libjpeg-devel
  • zlib-devel
  • python3-devel
  • python3-setuptools(用于运行easy-install-3.6
我还使用以下命令安装了pip:
easy-install-3.6 install pip

最后:

pip3 install pillow

成功了。


谢谢您提供的解决方案。在Cygwin下,我使用Python2.7也成功了。只需要按照相同的步骤安装python2-devel和python2-setuptools即可。 - paperazzo79

4
根据文档所述:
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

根据您的安装情况,您可能需要将 python3 替换为 pypy3python

对我而言,仅使用简单的 pip install Pilloweasy_install Pillow 并不起作用,后者会报告无法安全地安装 EasyInstall。


3
pip install wheel
pip install Pillow

对我很有效


2
错误消息底部的URL如下:

Windows安装 我们为支持的Python版本矩阵编译的32位和64位版本的Pillow二进制文件提供轮子、蛋和可执行安装程序。这些二进制文件包括所有可选库:

pip install Pillow

我建议尝试使用它,以避免出现像您遇到的依赖问题。
编辑:Pillow仅支持Pillow >= 2.0.0 < 3.5.0而不是3.6.0
编辑:希望这能够起作用,我无法在Windows上进行实际测试。

我已经尝试了'pip install Pillow',但它仍然给我相同的zlib错误信息: self.build_extensions() File "C:\Users\GThell\AppData\Local\Temp\pip-build-y8vx01vv\Pillow\setup.py", line 521, in build_extensions ' using --disable-%s, aborting' % (f, f)) ValueError: zlib是必需的,除非使用--disable-zlib明确禁用,否则将中止。 - GTHell
你检查过你的Python版本是否兼容吗?"Pillow >= 3.5.0支持Python版本2.7、3.3、3.4、3.5"(没有列出3.6,这可能是一个问题)http://pillow.readthedocs.io/en/latest/installation.html - Alex G Rice
啊哈,我不知道Python在不同版本之间是有区别的。我的版本是3.6.0。我需要卸载Python或者只是下载3.5.0版本吗?谢谢。 - GTHell
我可能会卸载3.6,因为最新的稳定版本实际上是3.5.2 :) - Alex G Rice

1
在Windows上,与其从源代码构建,不如使用预编译的二进制文件(wheels)更好。 Python 3.6.0 最终版将于本周稍后发布(2016-12-23),而 Pillow 还不支持它。希望在下一个季度的发布中得到支持,即 2017 年 1 月 1 日。 然而,在此期间,您可以从这里下载非官方的 wheel 文件,然后使用 pip install filename.whl 安装。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow


1
您可以尝试使用Pillow的Windows安装程序包进行安装。
请检查https://pypi.org/project/Pillow/#files,Windows安装程序包位于页面底部。
我使用Python 3.7成功安装。

哇塞,非常感谢!我一直陷入了一个无尽的循环中:“由于y无法安装x,由于z无法安装y,由于aa无法安装z”,而这个终于解决了我的问题。 - mauve

0
在Windows系统中,由于框架问题,有些软件包可能无法正常工作。但是可以通过第三方网站下载并使用它们。 非官方Python二进制文件提供了相应版本的下载。
选择对应版本进行下载。
然后例如,
pip install Downloads\\Pillow.whl

现在它将无错误地安装


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接