IMX298 works with python 2.7 but not with python 3.7.3

I am running an IMX298 on a Raspberry Pi 4B 8GB and would like to run it in python 3.7.3. However, it generates the error below. It works fine in python 2.7.16. I need to use python 3 because of other components that need to be integrated so don’t have the option of simply using Python 2.7.

Any suggestions would be much appreciated, as the fact that it works in Python 2.7 suggests it’s something to do with Python 3 compatibility and not OpenCV.

Open camera…
Found sensor imx298 at address 1A
sensor id : 298

set imx298 gain register

Setting the mode…
Can’t open the file
mmal: Failed to fix lens shading, use the default mode!
Current resolution is (1160, 800)
Reset the focus…
OpenCV(4.4.0) /tmp/pip-install-2acr15s4/opencv-python/opencv/modules/highgui/src/window.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvShowImage’


Which demo are you using? I will help you test and reply you as soon as possible.

Please tell me your detail operation steps.



I’m having the problem with any of the demos that I try to run as python3 from the ISP folder. It works on and from the python folder, having just checked it.

As far as operational steps are concerned, all I’m doing is running the file name with python3 instead of python directly from the ISP folder at this stage.

Thanks for your help.


It seems the opencv’s version is old. Please try

sudo apt-get install libopencv-dev

pip3 uninstall opencv-python

pip3 install opencv-python

Then retry it again.

Let me know if you need more help.


Thank you. Sorry about the slow reply, it took quite a while to install and uninstall different versions to do a proper check. I have tried the latest OpenCV version available (4.4.0), as well as the 4.3.0 and 3.4.11 but it keeps doing the same thing. I could not install, which is the lowest version listed in the install options. It is presumably incompatible with the installed Python version (3.7.3).

I will try to get around the problem with doing external calls in the meantime but thought to let you know it’s still not working. The demo runs with OpenCV 3.2.0 through Python 2.7.16, so I’m not sure where the problem might be with the Python 3 installation.

Thanks a lot for your help.


I will help you test it using the newest firmware. I probably won’t be able to test it until late next week, because I’ll be on a business trip recently. I am sorry to take up your time.



Thank you, that sounds great. I will keep an eye out for any fixes and try to work around it in the meantime. I understand that it’s difficult to keep up with everything.


Thanks for your patience. I have tested it and the result is the same as yours. The python2.7 can work normally.

My system does not have opencv-python4 version, I am installing it and try and reply you as soon as possible.



Thank you. I think I have found the problem (within the last hour). It seems that if one uses pip3 install it doesn’t install the full version of OpenCV and some of the necessary files are missing, so one has to compile it from source as a full installation for it to work properly.


Thank you, that sounds great.