pillow安装失败问题

在Linux环境下尝试使用pip安装Pillow时遇到错误,提示缺少Python.h头文件。该问题源于Pillow 3.0.0及以上版本需要Python开发库支持。解决方案包括确保已安装GCC和Python开发包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用pip install pillow命令时,安装出错,提示如下:

 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -Isrc/Tk -I/tmp/pip-install-xr8nqb_8/pillow/src/libImaging -I/tmp/pip-install-xr8nqb_8/pillow -I/usr/include -I/usr/include/python3.6m -c src/_imagingtk.c -o build/temp.linux-x86_64-3.6/src/_imagingtk.o
    src/_imagingtk.c:16:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    src/_imaging.c:74:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    building 'PIL._imagingmath' extension
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/tmp/pip-install-xr8nqb_8/pillow/src/libImaging -I/tmp/pip-install-xr8nqb_8/pillow -I/usr/include -I/usr/include/python3.6m -c src/_imagingmath.c -o build/temp.linux-x86_64-3.6/src/_imagingmath.o
    building 'PIL._imagingmorph' extension
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/tmp/pip-install-xr8nqb_8/pillow/src/libImaging -I/tmp/pip-install-xr8nqb_8/pillow -I/usr/include -I/usr/include/python3.6m -c src/_imagingmorph.c -o build/temp.linux-x86_64-3.6/src/_imagingmorph.o
    src/_imagingmath.c:16:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    src/_imagingmorph.c:14:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-xr8nqb_8/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-record-0wrtmkzl/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-xr8nqb_8/pillow/
FATAL: Failed installing package pillow

找不到Python.h头文件,没有gcc之类的问题其实都是因为从Pillow 3.0.0.开始需要libjpeg 和 zlib两个包才能编译,现在下载的Pillow里没有这两个包,所以下载失败

换个指令下载就行:

pip install --upgrade pillow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值