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

**URL:** <https://forum.opencv.org/t/build-fatal-error-python-h-no-such-file-or-directory/15485>\
**Category:** C++\
**Tags:** raspberrypi, build\
**Created:** [November 12, 2023, 4:53pm UTC](https://forum.opencv.org/t/build-fatal-error-python-h-no-such-file-or-directory/15485 "2023-11-12T16:53:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![baqwas](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@baqwas](https://forum.opencv.org/u/baqwas)\
**Post date:** [November 12, 2023, 4:53pm UTC](https://forum.opencv.org/t/build-fatal-error-python-h-no-such-file-or-directory/15485/1 "2023-11-12T16:53:11Z")

</div>

Hello!

The standard response for _“fatal error: Python.h” No such file or directory_ does not seem to work for my platform.

I have cloned the opencv repository:

```auto
On branch 4.x
Your branch is up to date with 'origin/4.x'.

```

After using ccmake/cmake with default settings, my make fails with the following error message:

```auto
[100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
In file included from /home/chowkidar/projects/opencv/modules/python/src2/cv2.cpp:5:
/home/chowkidar/projects/opencv/modules/python/src2/cv2.hpp:20:10: fatal error: Python.h: No such file or directory
   20 | #include <Python.h>
      | ^ ~~~~~~~~~
compilation terminated.

```

My configuration is:

```auto
$ python3 --version
Python 3.11.2
$ which python3
/usr/bin/python3
$ sudo apt install libpython3-dev
libpython3-dev is already the newest version (3.11.2-1+b1).
$ sudo apt install python3-dev
python3-dev is already the newest version (3.11.2-1+b1).
$ g++ --version
g++ (Debian 12.2.0-14) 12.2.0
$ uname -a
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
OS: Debian GNU/Linux 12 (bookworm) aarch64
Host: Raspberry Pi 3 Model B Rev 1.2
$ find / | grep "Python.h"
/usr/include/python3.11/Python.h

```

ccmake is pointing to the following Python3 include directory:  
` PYTHON3_INCLUDE_DIR /usr/include/python3.11`

What is the simplest way to turn off compilation for **opencv\_contrib** using ccmake/cmake but ensure all opencv core programs are built so that I can make progress on a basic build? Thanks.

Regards.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 12, 2023, 5:24pm UTC](https://forum.opencv.org/t/build-fatal-error-python-h-no-such-file-or-directory/15485/2 "2023-11-12T17:24:50Z")

</div>

please add:

- os, opencv version
- your cmake cmdline, and resp. output
- do you actually _whish_ for python support ? (why not use pip ?)
- why are you trying to disable contrib modules ?

---

<div class="post-metadata">

**Author:** ![baqwas](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@baqwas](https://forum.opencv.org/u/baqwas)\
**Post date:** [November 12, 2023, 9:15pm UTC](https://forum.opencv.org/t/build-fatal-error-python-h-no-such-file-or-directory/15485/3 "2023-11-12T21:15:59Z")

</div>

@berak,

Here are some quick responses to your question:  
**os** : Raspberry Pi OS a.k.a. Debian GNU/Linux 12 (bookworm) aarch64 (as listed in the original note)  
**opencv version** : Release 61, 4.8.1 (noted _implicitly_ in the original note)  
cmake cmdline: you would really need the CMakeCache.txt? cmdline, per se, is cmake …/opencv where the build folder and the opencv source are separate  
**do you actually…?** : want to build from source (I understand what you are saying, of course, but don’t want to go off-topic)  
**why are you…?** : unproven _hunch_ that the problem may lie with a contrib make file

Thanks.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 13, 2023, 5:51am UTC](https://forum.opencv.org/t/build-fatal-error-python-h-no-such-file-or-directory/15485/4 "2023-11-13T05:51:34Z")

</div>

there are python3 cmake args, so, how did you invoke it, and what did it print out ?

---

<div class="post-metadata">

**Author:** ![baqwas](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@baqwas](https://forum.opencv.org/u/baqwas)\
**Post date:** [November 14, 2023, 2:19am UTC](https://forum.opencv.org/t/build-fatal-error-python-h-no-such-file-or-directory/15485/5 "2023-11-14T02:19:13Z")

</div>

Hello @berak,

My apologies for wasting everyone’s time. The issue has been resolved. I have a nightly Ansible playbook that runs _update/upgrade_ in the farm that may have fixed something - purely an ignorant guess. The preceding _git_ operations didn’t _pull_ anything fresh from the _master_ so it was clearly my issue alone.

The error message was generated at the 100% mark for opencv\_version as noted in the original note. This afternoon’s run for the _make_ had no errors:

`[100%] Built target opencv_version`

The subsequent _sudo make install_ listed the following corresponding line:

`-- Up-to-date: /usr/local/bin/opencv_version`

And, of course, the proof is the following validation:

```auto
$ python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2. __version__'4.8.0-dev'
>>> exit()

```

Many, many thanks for the positive responses here. Can’t express how much I appreciate it. Thanks.

Regards.  
**P.S.**  
On a personal note, I have being doing builds with OpenCV source since 2014 with varying challenges. I have stopped doing builds on the older RPi boards because the pre-built packages now come out very quickly. However, I just like to learn a little bit more now and then, and therefore limit myself to RPi 3 & 4 boards for the build from source.
