Python3.9 -m pip install pycairo failing

when I do python3.9 -m pip install pycairo

I get this error

Building wheels for collected packages: pycairo
  Building wheel for pycairo (pyproject.toml) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.9 /usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmpoxwx0u28
       cwd: /tmp/pip-install-ga_h3n8o/pycairo_16228bbec418464c8ec33eb965343984
  Complete output (19 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/cairo
  copying cairo/__init__.py -> build/lib.linux-x86_64-3.9/cairo
  copying cairo/__init__.pyi -> build/lib.linux-x86_64-3.9/cairo
  copying cairo/py.typed -> build/lib.linux-x86_64-3.9/cairo
  running build_ext
  building 'cairo._cairo' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/cairo
  gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=20 -DPYCAIRO_VERSION_MICRO=1 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/uuid -I/usr/include/python3.9 -c cairo/bufferproxy.c -o build/temp.linux-x86_64-3.9/cairo/bufferproxy.o -Wall -Warray-bounds -Wcast-align -Wconversion -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Winline -Wmissing-format-attribute -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-arith -Wreturn-type -Wshadow -Wsign-compare -Wstrict-aliasing -Wundef -Wunused-but-set-variable -Wswitch-default -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-command-line-argument -fno-strict-aliasing -fvisibility=hidden -std=c99
  cairo/bufferproxy.c:32:10: fatal error: Python.h: No such file or directory
   #include <Python.h>
            ^~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pycairo
Failed to build pycairo
ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects

I checked the requirement there Getting Started — Pycairo documentation

dnf --enablerepo=* install cairo-devel pkg-config python3-devel
Last metadata expiration check: 0:00:35 ago on Thu 28 Oct 2021 06:56:44 PM EDT.
Package cairo-devel-1.15.12-3.el8.x86_64 is already installed.
Package pkgconf-pkg-config-1.4.2-1.el8.x86_64 is already installed.
Package python36-devel-3.6.8-2.module_el8.3.0+6191+6b4b10ec.x86_64 is already installed.

How can I install pycairo ?

Long live linuxbrew (homebrew)

in fact it’s this GitHub - adefossez/seewav: Audio waveform visualisation, converts any audio to a nice video that needed pycairo

In my almalinux I installed linuxbrew for ffmpeg and many other…

I managed to /home/linuxbrew/.linuxbrew/opt/python@3.9/bin/python3.9 -m pip install seewav

and then use
/usr/bin/python3.9 /home/linuxbrew/.linuxbrew/lib/python3.9/site-packages/seewav.py in.aiff out.mp4

I know it’s a VERY weird workaround but it works great

Recommendation: Keep different things separate.
Have only one system manage files in system directories: dnf
Keep everything else in user directories.

Recommendation: Never build as root.

command: /usr/bin/python3.9 /usr/local/lib/python3.9/site-packages ...

Regular user can’t write to /usr/local. Running pip as root does unknown things to files.
Rather create Python venv and pip in it as regular user.

fatal error: Python.h: No such file or directory

Who has Python.h?

dnf provides */Python.h

The answer is long. However, you run python3.9, so this result is appropriate:

python39-devel-3.9.2-1.module_el8.4.0+2374+27ce8e03.x86_64 : Libraries and header files needed for Python development
Repo        : appstream
Matched from:
Filename    : /usr/include/python3.9/Python.h

That is the package that you should have, rather than “python3-devel/python36-devel”.

I’m not not using root. There is issues with trying to install gpg, osgeo, pycairo, seewav, gdal, …

dnf provides */Python.h | grep 3.9

python39-devel-3.9.2-1.module_el8.4.0+2374+27ce8e03.x86_64 : Libraries and header files needed for Python development
Filename    : /usr/include/python3.9/Python.h
ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4muu1mlp/gpg_5f1b2d644c2e48feae375007df49b024/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4muu1mlp/gpg_5f1b2d644c2e48feae375007df49b024/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-mntz902v/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/stubfeed/.local/include/python3.9/gpg
         cwd: /tmp/pip-install-4muu1mlp/gpg_5f1b2d644c2e48feae375007df49b024/
    Complete output (9 lines):
    running install
    running build
    Using gpgme.h from /usr/include/gpgme.h
    running build_ext
    building 'gpg._gpgme' extension
    swigging build/gpgme.i to build/gpgme_wrap.c
    swig -python -threads -py3 -Ibuild -outdir build/lib.linux-x86_64-3.9/gpg -o build/gpgme_wrap.c build/gpgme.i
    build/gpgme.h:16: Error: CPP #error ""unexpected value for __WORDSIZE macro"". Use the -cpperraswarn option to continue swig processing.
    error: command '/usr/bin/swig' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4muu1mlp/gpg_5f1b2d644c2e48feae375007df49b024/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4muu1mlp/gpg_5f1b2d644c2e48feae375007df49b024/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-mntz902v/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/stubfeed/.local/include/python3.9/gpg Check the logs for full command output.
ERROR: Command errored out with exit status 1:
   command: /usr/bin/python /home/stubfeed/.local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmptrrbmgsq
       cwd: /tmp/pip-install-0giix8qo/pycairo_60032cb16f6b4a06a0eef8cf59cf7c3a
  Complete output (19 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/cairo
  copying cairo/__init__.py -> build/lib.linux-x86_64-3.9/cairo
  copying cairo/__init__.pyi -> build/lib.linux-x86_64-3.9/cairo
  copying cairo/py.typed -> build/lib.linux-x86_64-3.9/cairo
  running build_ext
  building 'cairo._cairo' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/cairo
  gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=20 -DPYCAIRO_VERSION_MICRO=1 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/uuid -I/usr/include/python3.9 -c cairo/bufferproxy.c -o build/temp.linux-x86_64-3.9/cairo/bufferproxy.o -Wall -Warray-bounds -Wcast-align -Wconversion -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Winline -Wmissing-format-attribute -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-arith -Wreturn-type -Wshadow -Wsign-compare -Wstrict-aliasing -Wundef -Wunused-but-set-variable -Wswitch-default -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-command-line-argument -fno-strict-aliasing -fvisibility=hidden -std=c99
  cairo/bufferproxy.c:32:10: fatal error: Python.h: No such file or directory
   #include <Python.h>
            ^~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pycairo
Failed to build pycairo
ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects
ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-enu9f5jl/osgeo_9faeac0540e14926835fc0001f7020bb/setup.py'"'"'; __file__='"'"'/tmp/pip-install-enu9f5jl/osgeo_9faeac0540e14926835fc0001f7020bb/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-q36ya0b_/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/stubfeed/.local/include/python3.9/osgeo
         cwd: /tmp/pip-install-enu9f5jl/osgeo_9faeac0540e14926835fc0001f7020bb/
    Complete output (18 lines):
    running install
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-enu9f5jl/osgeo_9faeac0540e14926835fc0001f7020bb/setup.py", line 32, in <module>
        setup(
      File "/home/stubfeed/.local/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib64/python3.9/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib64/python3.9/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-install-enu9f5jl/osgeo_9faeac0540e14926835fc0001f7020bb/setup.py", line 27, in run
        raise Exception(error_msg)
    Exception: In order to be able to run `from osgeo import gdal`,
    You were probably trying to install `gdal` by running `pip install osgeo`.
    Instead, you should either `pip install gdal` or replace `osgeo` with `gdal` in your requirements.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-enu9f5jl/osgeo_9faeac0540e14926835fc0001f7020bb/setup.py'"'"'; __file__='"'"'/tmp/pip-install-enu9f5jl/osgeo_9faeac0540e14926835fc0001f7020bb/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-q36ya0b_/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/stubfeed/.local/include/python3.9/osgeo Check the logs for full command output.

I was able to install pycairo without any issues on the latest EL8 release:

[cairo@cairotest ~]$ dnf -y install cairo-devel pkg-config python39 python39-devel python39-pip
[cairo@cairotest ~]$ dnf -y groupinstall 'Development Tools'

[cairo@cairotest ~]$ python3.9 -m pip install pycairo
Defaulting to user installation because normal site-packages is not writeable
Collecting pycairo
  Using cached pycairo-1.20.1.tar.gz (344 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: pycairo
  Building wheel for pycairo (PEP 517) ... done
  Created wheel for pycairo: filename=pycairo-1.20.1-cp39-cp39-linux_x86_64.whl size=283952 sha256=66028c4de1292b5ccb2c3cd5af7e898e57a6a1cdb6faa030577a720de909e86c
  Stored in directory: /home/cairo/.cache/pip/wheels/29/a9/b9/15e3dc25ce0db1d40546014674ee0cac132f94bf3a9607d02b
Successfully built pycairo
Installing collected packages: pycairo
Successfully installed pycairo-1.20.1

For gdal I was also having issues. This may be another issue related to Python 3.9 however I’m not sure at a glance. There is a 3.6 version available under python3-gdal if you can use that version in the interim.

2 Likes

Hi nice,
python39-devel x86_64 3.9.2-1.module_el8.4.0+2374+27ce8e03 was missing in my linux

after that it was all good

1 Like