manim: Failed to build pycairo in ubuntu

I tried to search the problem in the issues in github and I found similar error, but in mac and I’m using Ubuntu 18.04.3 LTS. After did steps, I run the command: $ python3.7 -m pip install -r requirements.txt but , the terminal gives an error building pycairo:

Requirement already satisfied: argparse==1.4.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 1)) (1.4.0)
Requirement already satisfied: colour==0.1.5 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 2)) (0.1.5)
Requirement already satisfied: numpy==1.15.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 3)) (1.15.0)
Requirement already satisfied: Pillow==5.2.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 4)) (5.2.0)
Requirement already satisfied: progressbar==2.5 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 5)) (2.5)
Requirement already satisfied: scipy==1.1.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 6)) (1.1.0)
Requirement already satisfied: tqdm==4.24.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 7)) (4.24.0)
Requirement already satisfied: opencv-python==3.4.2.17 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 8)) (3.4.2.17)
Collecting pycairo==1.17.1 (from -r requirements.txt (line 9))
  Using cached https://files.pythonhosted.org/packages/68/76/340ff847897296b2c8174dfa5a5ec3406e3ed783a2abac918cf326abad86/pycairo-1.17.1.tar.gz
Requirement already satisfied: pydub==0.23.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 10)) (0.23.0)
Building wheels for collected packages: pycairo
  Building wheel for pycairo (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-835za1sc/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-835za1sc/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-rjtho98i --python-tag cp37
       cwd: /tmp/pip-install-835za1sc/pycairo/
  Complete output (19 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.7
  creating build/lib.linux-x86_64-3.7/cairo
  copying cairo/__init__.py -> build/lib.linux-x86_64-3.7/cairo
  copying cairo/__init__.pyi -> build/lib.linux-x86_64-3.7/cairo
  copying cairo/py.typed -> build/lib.linux-x86_64-3.7/cairo
  running build_ext
  building 'cairo._cairo' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/cairo
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=17 -DPYCAIRO_VERSION_MICRO=1 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/python3.7m -c cairo/device.c -o build/temp.linux-x86_64-3.7/cairo/device.o -Wall -Warray-bounds -Wcast-align -Wconversion -Wdeclaration-after-statement -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
  cairo/device.c:30:10: fatal error: Python.h: Arquivo ou diretório inexistente
   #include <Python.h>
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pycairo
  Running setup.py clean for pycairo
Failed to build pycairo
Installing collected packages: pycairo
  Found existing installation: pycairo 1.16.2
ERROR: Cannot uninstall 'pycairo'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Then, I tried to switch to pycairo 1.16.2 in requirements and it works, but, after trying the command $ python3.7 -m manim example_scenes.py SquareToCircle -pl but, it gives me the problem of no module named apt_pkg and no module named cairo._cairo

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/satoshi/Downloads/InstallManin/manin/manim.py", line 3, in <module>
    import manimlib.extract_scene
  File "/home/satoshi/Downloads/InstallManin/manin/manimlib/extract_scene.py", line 9, in <module>
    from manimlib.scene.scene import Scene
  File "/home/satoshi/Downloads/InstallManin/manin/manimlib/scene/scene.py", line 11, in <module>
    from manimlib.camera.camera import Camera
  File "/home/satoshi/Downloads/InstallManin/manin/manimlib/camera/camera.py", line 9, in <module>
    import cairo
  File "/usr/lib/python3/dist-packages/cairo/__init__.py", line 1, in <module>
    from ._cairo import *  # noqa: F401,F403
ModuleNotFoundError: No module named 'cairo._cairo'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/satoshi/Downloads/InstallManin/manin/manim.py", line 3, in <module>
    import manimlib.extract_scene
  File "/home/satoshi/Downloads/InstallManin/manin/manimlib/extract_scene.py", line 9, in <module>
    from manimlib.scene.scene import Scene
  File "/home/satoshi/Downloads/InstallManin/manin/manimlib/scene/scene.py", line 11, in <module>
    from manimlib.camera.camera import Camera
  File "/home/satoshi/Downloads/InstallManin/manin/manimlib/camera/camera.py", line 9, in <module>
    import cairo
  File "/usr/lib/python3/dist-packages/cairo/__init__.py", line 1, in <module>
    from ._cairo import *  # noqa: F401,F403
ModuleNotFoundError: No module named 'cairo._cairo'

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 16

Commits related to this issue

Most upvoted comments

I got the same problem during the installation and these commands solved the problem.

sudo apt-get install pkg-config
sudo apt-get install libcairo2-dev
cairo/device.c:30:10: fatal error: Python.h: No such file or directory
#include <Python.h>
        ^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pycairo
Running setup.py clean for pycairo
Failed to build pycairo

In my case, Installing python3.7-dev solved the problem.

sudo apt install python3.7-dev

I got the same problem during the installation and these commands solved the problem.

sudo apt-get install pkg-config
sudo apt-get install libcairo2-dev

This fixed the issue for me on WSL, although my error looked like:

  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/cairo
  copying cairo/__init__.py -> build/lib.linux-x86_64-3.6/cairo
  copying cairo/__init__.pyi -> build/lib.linux-x86_64-3.6/cairo
  copying cairo/py.typed -> build/lib.linux-x86_64-3.6/cairo
  running build_ext
  'pkg-config' not found.
  Command ['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']

  ----------------------------------------
  Failed building wheel for pycairo
  Running setup.py clean for pycairo
Failed to build pycairo
Installing collected packages: tqdm, numpy, opencv-python, pydub, progressbar, pycairo, scipy, pygments, Pillow, argparse, colour, manimlib
  Running setup.py install for pycairo ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-km3wpzjk/pycairo/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-vamm5ock-record/install-record.txt --single-version-externally-managed --compile --user --prefix=:
    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/cairo
    copying cairo/__init__.py -> build/lib.linux-x86_64-3.6/cairo
    copying cairo/__init__.pyi -> build/lib.linux-x86_64-3.6/cairo
    copying cairo/py.typed -> build/lib.linux-x86_64-3.6/cairo
    running build_ext
    'pkg-config' not found.
    Command ['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-km3wpzjk/pycairo/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-vamm5ock-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-km3wpzjk/pycairo/```

My solution:
sudo apt install gcc

Then, install the newest manimpango: pip install manimpango==0.2.6

cairo/device.c:30:10: fatal error: Python.h: No such file or directory
#include <Python.h>
        ^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pycairo
Running setup.py clean for pycairo
Failed to build pycairo

In my case, Installing python3.7-dev solved the problem.

sudo apt install python3.7-dev

Thanks a lot Worked for me