Make Error with v4.5.4 under Bullseye/Raspberry Pi Model B

Hello,

I’ve done make many, many times on a Raspberry Pi B over the years with whatever clone was current from GitHub. I recently upgraded to Bullseye (from Buster). Did a refresh using ccmake … and cmake . and had a minor issue to attend to (viz. gcc-10 was installed but there was no link to g++; resolved by re-installing build-essential).

In running make, right at the end I received the following error message:

[100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
/home/pi/projects/opencv/modules/python/src2/cv2.cpp:17:10: fatal error: Python.h: No such file or directory
   17 | #include <Python.h>
      |          ^~~~~~~~~~
compilation terminated.
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:82: modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:5101: modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make: *** [Makefile:182: all] Error 2

I am a total newbie with OpenCV source; I can run the examples modestly (in Python and C/C++). The above error seems to be some issue with references in my configuration. I don’t inspect the Makefile.txt at all but do make some changes through ccmake depending on the hardware platform that is under study and personal interest in understanding some OpenCV features. As you can see from the subject field, this hardware platform is rather old but in the long run I’ve always succeeded in getting OpenCV built with plenty of patience.

I need help to fix this issue, please! The message is understandable but, of course, I have zero knowledge on where to start! Appreciate any guidance. Thanks.

Kind regards.

Probably you somehow misconfigured Python bindings. Do you have python3-dev (or similar) package installed? Did you set any Python-related variables in cmake, maybe some are wrong or missing? Did you try a clean build?

Do you have python3-dev (or similar) package installed?
Yes, Python3 is the workhorse on this platform. I just noticed that Bullseye jumped the version from 3.7 to 3.9! Perhaps, that did unlink something but I have no understanding here of how to recover.

Did you set any Python-related variables in cmake, maybe some are wrong or missing?
Didn’t change anything in ccmake that is directly linked to any Python setting. I use cmake without further changes from the preceding ccmake step. Python2 was disabled in a previous build (the one that was successful prior to the current git pull origin main). So perhaps there is some unlinking (unknown to me) going on with the system change from Python 3.7 to Python 3.9.

Did you try a clean build?
I always have to make changes through ccmake owing the limitations of the ARM6l hardware platform. So, pardon me, I am not following what would constitute a clean build. I refreshed the local sources in May/June and the same set of commands (ccmake, cmake, make, make install) worked without breaking issues but I thought that the Makefile in the ./opencv/build sub-folder is never touched by the refresh. The only new module that I’m trying with this build is Eigen3 that I had omitted previously.

Do let me know if you spot anything in my responses that you feel requires me to take a few steps back. It takes almost 18 hours :grinning: to do a build on this old machine (but it is worth it, I must confess). Thanks.

Kind regards.

I’m talking about python3-dev package specifically, it should contain Python.h file. apt list python3-dev command should hsow it as [installed].

clean build means you remove build directory and create a new one. Changes in the code (git pull) or configuration (packages installed/removed, options changed) can result in broken build directory contents and cmake scripts usually do not cover these cases.

For better reproducibility I’d recommend using cmake directly, avoiding ccmake. Once you know which options you need it is easy to use them in cmake command line (in shell script), e.g. cmake -DBUILD_opencv_python2=OFF .. && cmake --build ..

And I’d recommend using cross-compilation on regular machine, it can be tricky to setup but the time spent should be less than 18hrs :slight_smile: . You will need Docker-container based on same Debian version with cross-compilation tools installed (g+±10-arm-linux-gnueabi and some others). Some command-line options can be found in buildbot logs. Major problem of cross-compilation is linking with dependencies matching your target platform, but it should be possible. There are many other guides and methods in the internet, e.g. Cross-Compiling for Raspberry Pi - Kitware Blog

Hello @mshabunin,

Thanks for the advice. Appreciate ALL of it. I will work in step-wise fashion with your notes. Your first paragraph makes sense because I had to reinstall build-essential. Therefore I shouldn’t take python3-dev for granted. I think this suggestion is the problem solver, IMHO.

Your other suggestions are excellent too. My desktop required only 16 mins to build OpenCV early this year. Bypassing ccmake makes a lot sense except that specifically for the RPiB (almost 8 years old and still going strong) but there are some granular selections that are needed for the apps on that board only. OpenCV has done a lot of improvement in this respect (especially with the transition to Python3 by default).

Thanks very much for the links. Now that I know I have access to HELP, I’ll take the plunge with cross-compilation. I had so many problems with it for IoT devices from OnSemi that I had to stop.

Kind regards.

Hello again @mshabunin,

Thanks to you I found the error! The Makefile was still pointing to python3.7m folder instead of python3.9 where the header file was located.

Kind regards.

1 Like