I have been trying to install the Pillow package using pip (python version 3.6, Pillow version 8.4, Linux virtual machine). Several other answers have suggested installing the developer package but I do not have sudo privileges.
I am getting "fatal error: Python.h: no such file or directory" with "error: command 'gcc' failed with exit status 1"
I have tried both:
python3 -m pip install Pillow
and
python3 -m pip install Pillow --upgrade
Both give the below output/error (>20 successful compilation lines were omitted to meet submission requirements)
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