Solvedmanim 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'
17 Answers

✔️Accepted Answer

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

Other Answers:

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

Related Issues:

23
manim Failed to build pycairo in ubuntu
I got the same problem during the installation and these commands solved the problem. ...
521
ant motion 模版代码下载下来导入到dva搭建的项目里面,启动时报错(npm start)
开启 JavaScript 就可以了 你好,我下载的Home项目引入到项目工程里面,为了方便,我全部放到了components下面,引入和基本流程没有问题。在家里的win10上面启动没有报错,在win...
156
react native modal The statusbar turns white when the modal is open (only on certain devices)
statusBarTranslucent property has been added to Modal of RN 0.62 I think this problem has been solve...
138
lottie ios animation stop after enter background
Seem we have this to pause in background and restart when it reach foreground animationView.backgrou...
76
react native circular progress No component found for view with name "ARTSurfaceView"
I drag and dropped node_modules/react-native/Libraries/ART/ART.xcodeproj somewhere to my Xcode proje...
65
react native reanimated V2: Upgrade error InnerNativeModule.installCoreFunctions
was facing same problem react-native: 0.66.0 react-native-reanimated: ^2.3.0-beta.2 ...
61
uCrop FileUtils NumberFormatException
This is not a complete solution just nothing will happen But I think users should be able to open fi...
52
react native modal Error property 'left' is not supported by native animated module when using swipe
This is not due to react native limitations Keeping it as simple as the above ...
50
react native reanimated RN 0.61 Android build fails
I am still facing this This likely has to do with AndroidX or other things of which I am somewhat ig...
46
react native circular progress Invariant Violation: requireNative Component: "RNSVGPath" was not found in the UIManager
for any future person coming here with this issue that I faced on Android make sure to recompile you...
36
moviepy ImageMagick not detected by moviepy while using SubtitlesClip
comment out (or remove the line that reads) <policy domain=path rights=none pattern=@* /> <!-- <poli...
36
react native modal Tap outside to close
@Doko-Demo-Doa according to the source code haven't implemented yet there is no close event on backd...
29
react native modal How to avoid keyboard for bottom half modal
FWIW for those coming from Google Let's say we have a bottom half modal with some TextInput ...
29
react native reanimated TurboModuleRegistry NativeReanimated error
When loading with 2.0.0-alpha.8 I'm still running into ExceptionsManager.js:179 Invariant Violation:...
21
moviepy Unable to run the sample code! Getting errors. Plase Help
I just figured this out. imagemagick (ie convert) has a policy.xml file that stops you from accessin...
20
react native modal How could we add swipe down to close function?
+1 for this feature please Hi I love the way this module: https://github.com/maxs15/react-native-mod...
20
react native reanimated [Jest] V2 - rc2 Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'NativeReanimated'
I opened a PR but if you guys want a temporary fix Use ds300/patch-package and put this on patches/r...
18
react native reanimated Unable to resolve module ./abs
@jakub-gonet I think in my case watchman was the culprit as even after --reset-cache the issue was s...
16
barba Update body class?
Got it working with events too: Is it possible to update the body class between transitions? ...
15
react native reanimated [RN 0.66] iOS build failure: 'boost/operators.hpp' file not found
Try react-native-reanimated: 2.3.0-beta.2 It has fix for search paths Description After updating to ...
13
react native modal error: bundling failed: Error: Unable to resolve module `./animations`
this command fixed my issue npm start -- --reset-cache I upgraded my react-native-modal from 7.0.2 t...
13
react native reanimated Android only -> E/ReactNativeJS: undefined is not an object (evaluating '_ReanimatedModule.default.configureProps')
Make sure that you've added new ReanimatedPackage(),in MainApplication.java under getPackages Import...
12
moviepy AttributeError: module 'moviepy.audio.fx.all' has no attribute 'audio_fadein'
For everyone that has the same issue i solved it by modifying the selected init file shown in the pi...
12
lottie android JSON Reader AssertionError when doInBackground (Android 7, 8)
We are having the same issues (Lottie 2.5.5) - only Android 8 So hope to find a fix soon ...
8
SkeletonView Wrong skeleton view width on iPhone 8 plus
Ok I've found my problem I was calling showSkeleton in viewDidLoad Moving it to viewDidAppear fixed ...
8
aseprite Skia build fails on Mojave
For me I have to use @adennen 's solution and also disable webp via skia_use_libwebp=false due to I ...
7
animated tab bar Major issue when using hidesBottomBarWhenPushed. Please investigate
@sentiasa Hi! It's very easy to solve this issue by using this: Hey guys ...
7
barba CF7 Wordpess reload
Hi The newest version of wpcf7 needs some code changes: Hi there ...
7
react native modal modal not begin from bottom
<Modal style={{ margin: 0 }}>....</Modal> can fix your problem I try to make modal that begin from b...
5
CompactCalendarView Show Event indicators to currently selected day
I've released a new beta version: Let me know if you have any feedback While Adding events to curren...
5
lottie ios Use image resources in lottie-ios
Hi guys I think the best solution is AnimationImageProvider Lottie has AnimationImageProvider I am s...
5
barba View afterEnter hook on browser refresh is not triggered
Fixed in @barba/core 2.3.15 Hi there! First of all thanks alot for the great work Using barba since ...
5
react three fiber Panning / Orbit Controls
@gino8080 you can also import OrbitalControl from drei I'm trying to implement a panning system on s...
5
svg.js svg rectangle with select resize and draggy
Oh cmon - you enable pointerevents on purpose for all elements with and then you wonder why the rect...
4
CompactCalendarView Remove First Day as SelectedDayBgColor
Added new xml property and method: Set that to false to not select first day of month Released anew ...
4
barba Uncaught (in promise) Error: xhr: HTTP code is not 200
I may have had some luck with this issue by passing a larger value to the XHR Timeout The default is...
3
SkeletonView SkeletonView not working in TableViewCell with custom class
@pennywise94 I ran into this issue too; the giant solid happens because calling showSkeleton() on a ...
3
FluidTransitions willBlur, didBlur listener not call
Experiencing this again with react-navigation@3.1.0 Perhaps an issue in react-navigation See this th...
3
react three fiber ✍️ Roadmap for 2.x (suggestions welcome)
@samburgers with the last commits that went in you can do this easily Just keep configs in state and...
926
keras Loading model with custom loss function: ValueError: 'Unknown loss function'
I solved this problem by adding 'custom_bojects' my loss function: I trained and saved a model that ...
731
scrapy ' error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 '
@euler16 for scrapy with Python 3 you'll need with Python 2 you'll need I wanted to install scrapy i...
633
keras Tensorflow backend - bug in model._make_predict_function(...)
I had this problem when doing inference in a different thread than where I loaded my model ...
575
mysqlclient Can't install mysqlclient on MacOS
You can set ssl library path explicitly. Hi I'm on MacOSX Sierra ...
516
keras Creating Model variable throws "AttributeError: 'Tensor' object has no attribute '_keras_history'"
@zaid478 oh I assumed you were doing it on coursera Anyway Hello all setup: Keras 2.0 Tensorflow 1.0...
456
tensorflow ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
@rhinsall I just found this out myself not sure if it's common knowledge but got around this by doin...
423
ipython Last jedi release (0.18.0) is incompatible with ipython (7.19 and 7.18 tested); reason - column arg was deprecated, and now removed
As a temporary fix for anyone just trying to get things working again: It would be really nice if yo...
416
pyodbc pip install pyodbc failing: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory #include <sql.h> ^ Your machine do...
395
keras "<tensor> is not an element of this graph." when loading model.
I had a problem similar to that of @piraka9011 which was solved by calling model._make_predict_funct...
392
psycopg2 psycopg2-binary fails to install on macOS Big Sur 11.0.1 and Python 3.9.0 (with possible workaround)
Actually figured it out Haven't worked on a Mac in a while and forgot about the PostgreSQL dependenc...