簡體   English   中英

無法在 Linux 中使用 pip 安裝 Pillow(錯誤:命令“gcc”失敗,退出狀態為 1)

[英]Unable to install Pillow with pip in Linux (error: command 'gcc' failed with exit status 1)

我一直在嘗試使用 pip(python 版本 3.6,Pillow 版本 8.4,Linux 虛擬機)安裝 Pillow 包。 其他幾個答案建議安裝開發人員包,但我沒有 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

查看最新 Pillow 版本可用的輪子,我可以看到 Python 3.6 沒有輪子。 Python 3.7 是受支持的最舊版本。

一種解決方案是升級 Python(3.6 已經很舊了。)或安裝舊版本的 Pillow。 例如版本 8.4.0 有適用於 Python 3.6 的輪子,要獲得舊版本,請在使用pip安裝時指定版本號:

pip install Pillow==8.4.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM