“找不到 zlib 的头文件或库文件,这是从源代码编译 Pillow 时必需的依赖项”

问题描述 投票:0回答:3

我正在尝试使用 pyautogui 运行 Python 程序,但出现问题,因为它告诉我未安装 Pillow。我尝试使用诸如

之类的命令来安装或升级它
pip install Pillow --upgrade 

但没有任何效果。

在文档中他们说 Pillow 不与 PIL 共存,所以我们需要卸载它但我不能,因为它说它没有安装。

错误是:

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

还有

Collecting Pillow
  Using cached Pillow-9.2.0.tar.gz (50.0 MB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: Pillow
  Building wheel for Pillow (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
python pip python-imaging-library pyautogui
3个回答
3
投票

你需要

zlib-dev
。这将安装编译部分 Pillow 所需的头文件。

您可能会遇到与

jpeg
相同的消息;为此,您需要
libjpeg-turbo-dev
包。


0
投票

我在我的 Mac 上遇到了同样的问题。对我来说,运行以下命令后,它起作用了:

  1. brew install zlib
  2. brew install jpeg
  3. export LDFLAGS="-L/usr/local/opt/zlib/lib"
  4. export CPPFLAGS="-I/usr/local/opt/zlib/include"

-1
投票

如果你是 linux 用户,你可以这样做

pip install pillow

sudo apt install python3-pil
© www.soinside.com 2019 - 2024. All rights reserved.