无法在 Linux 中使用 pip 安装 Pillow(错误:命令“gcc”失败,退出状态为 1)

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

我一直在尝试使用pip安装Pillow包(python版本3.6,Pillow版本8.4,Linux虚拟机)。其他几个答案建议安装开发人员包,但我没有 sudo 权限。

我收到“致命错误:Python.h:没有这样的文件或目录”和“错误:命令'gcc'失败,退出状态为1”

我都尝试过:

python3 -m pip install Pillow

python3 -m pip install Pillow --upgrade

两者都给出以下输出/错误(省略了超过 20 条成功的编译行以满足提交要求)

Collecting Pillow
  Using cached https://files.pythonhosted.org/packages/7d/2a/2fc11b54e2742db06297f7fa7f420a0e3069fdcf0e4b57dfec33f0b08622/Pillow-8.4.0.tar.gz
Installing collected packages: Pillow
  Running setup.py install for Pillow ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-go2j0sv9/Pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-piu2gd0c-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/PIL
    copying src/PIL/IcnsImagePlugin.py -> build/lib.linux-x86_64-3.6/PIL
    # x20 copying lines removed
    running egg_info
    writing src/Pillow.egg-info/PKG-INFO
    writing dependency_links to src/Pillow.egg-info/dependency_links.txt
    writing top-level names to src/Pillow.egg-info/top_level.txt
    reading manifest file 'src/Pillow.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching '*.c'
    warning: no files found matching '*.h'
    warning: no files found matching '*.sh'
    warning: no previously-included files found matching '.appveyor.yml'
    warning: no previously-included files found matching '.clang-format'
    warning: no previously-included files found matching '.coveragerc'
    warning: no previously-included files found matching '.editorconfig'
    warning: no previously-included files found matching '.readthedocs.yml'
    warning: no previously-included files found matching 'codecov.yml'
    warning: no previously-included files matching '.git*' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    no previously-included directories found matching '.ci'
    writing manifest file 'src/Pillow.egg-info/SOURCES.txt'
    running build_ext
    building 'PIL._imaging' extension
    building 'PIL._imagingft' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6
    building 'PIL._imagingtk' extension
    creating build/temp.linux-x86_64-3.6/src
    creating build/temp.linux-x86_64-3.6/src
    creating build/temp.linux-x86_64-3.6/src/Tk
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/freetype2 -I/tmp/pip-build-go2j0sv9/Pillow -I/usr/include/fribidi -I/usr/include -I/usr/local/include -I/usr/include/python3.6m -c src/_imagingtk.c -o build/temp.linux-x86_64-3.6/src/_imagingtk.o
    creating build/temp.linux-x86_64-3.6/src/libImaging
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/freetype2 -I/tmp/pip-build-go2j0sv9/Pillow -I/usr/include/fribidi -I/usr/include -I/usr/local/include -I/usr/include/python3.6m -c src/_imagingft.c -o build/temp.linux-x86_64-3.6/src/_imagingft.o
    building 'PIL._imagingmath' extension
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/freetype2 -I/tmp/pip-build-go2j0sv9/Pillow -I/usr/include/fribidi -I/usr/include -I/usr/local/include -I/usr/include/python3.6m -c src/_imagingmath.c -o build/temp.linux-x86_64-3.6/src/_imagingmath.o
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ -DHAVE_LIBTIFF -DHAVE_XCB -DPILLOW_VERSION="8.4.0" -I/usr/include/freetype2 -I/tmp/pip-build-go2j0sv9/Pillow -I/usr/include/fribidi -I/usr/include -I/usr/local/include -I/usr/include/python3.6m -c src/_imaging.c -o build/temp.linux-x86_64-3.6/src/_imaging.o
    src/_imagingft.c:22:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    src/_imagingtk.c:15:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    src/_imagingmath.c:16:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    src/_imaging.c:75:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    building 'PIL._imagingmorph' extension
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/freetype2 -I/tmp/pip-build-go2j0sv9/Pillow -I/usr/include/fribidi -I/usr/include -I/usr/local/include -I/usr/include/python3.6m -c src/_imagingmorph.c -o build/temp.linux-x86_64-3.6/src/_imagingmorph.o
    src/_imagingmorph.c:14:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
python pip python-imaging-library
2个回答
2
投票

查看最新 Pillow 版本可用的 wheels,我可以看到 Python 3.6 没有轮子。 Python 3.7 是最旧的受支持版本。

解决方案是升级 Python(3.6 已经很旧了!)或安装旧版本的 Pillow。例如,8.4.0 版本有 Python 3.6 的轮子。要获取旧版本,请在安装时指定版本号

pip
:

pip install Pillow==8.4.0

0
投票

通常,更新

pip
setuptools
wheel
软件包即可解决问题。
详细信息:
setuptools
wheel
包用于通过pip安装python库。

更新点:

pip3 install --upgrade pip

然后;
设置工具和滚轮:
pip3 install --upgrade setuptools wheel

© www.soinside.com 2019 - 2024. All rights reserved.