pypy3.8安装Pillow时出现The headers or library files could not be found for zlib错误

报错如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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:
https://pillow.readthedocs.io/en/latest/installation.html

Traceback (most recent call last):
File "/tmp/pip-install-hc7ffxdd/pillow_691ead8a6a1c48d0b8d84a80470f3787/setup.py", line 1020, in
zip_safe=not (debug_build() or PLATFORM_MINGW),
File "/home/pypy/lib/pypy3.8/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/home/pypy/lib/pypy3.8/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/pypy/lib/pypy3.8/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/home/pypy/lib/pypy3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/home/pypy/lib/pypy3.8/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/home/pypy/lib/pypy3.8/distutils/command/install.py", line 552, in run
self.run_command('build')
File "/home/pypy/lib/pypy3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/pypy/lib/pypy3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/home/pypy/lib/pypy3.8/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/home/pypy/lib/pypy3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/pypy/lib/pypy3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/home/pypy/lib/pypy3.8/site-packages/setuptools/command/build_ext.py", line 79, in run
_build_ext.run(self)
File "/home/pypy/lib/pypy3.8/distutils/command/build_ext.py", line 343, in run
self.build_extensions()
File "/tmp/pip-install-hc7ffxdd/pillow_691ead8a6a1c48d0b8d84a80470f3787/setup.py", line 788, in build_extensions
raise RequiredDependencyException(f)
RequiredDependencyException: zlib

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 36, in
File "", line 34, in
File "/tmp/pip-install-hc7ffxdd/pillow_691ead8a6a1c48d0b8d84a80470f3787/setup.py", line 1033, in
raise RequiredDependencyException(msg)
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:
https://pillow.readthedocs.io/en/latest/installation.html

[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> Pillow

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

解决办法:

1
sudo apt-get install libjpeg-dev zlib1g-dev

重新安装:

1
pip3 install Pillow