Need help to install OpenCV with Tensorflow

Hi! I have been trying to install Tensorflow and OpenCV in the same virtual environment.
But realized that they both require different Numpy versions.

This are the error messages I have gotten back:

ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

opencv-python 4.12.0.88 requires numpy<2.3.0,>=2; python_version >= “3.9”, but you have numpy 2.3.3 which is incompatible.

tensorflow 2.16.2 requires numpy<2.0.0,>=1.26.0; python_version >= “3.12”, but you have numpy 2.3.3 which is incompatible.

Has anyone encountered similar issues and managed to resolve this?

It means opencv-python 4.12.0.88 is not compatible with tensorflow 2.16.2.

Are you okay to install any versions of opencv and tensorflow? What version of python you are using?

Hi Luis,

Thanks for the tip!
Was thinking of using an older Open CV that uses Numpy 1.
But managed to get both of the latest packages to work together when I used the UV package manager.
Not sure how UV does it, but its all good now.

1 Like

The issue occurs because TensorFlow 2.16.2 requires NumPy <2.0.0,>=1.26.0, while OpenCV 4.12.0.88 requires NumPy >=2,<2.3.0, creating an incompatible overlap.

Install NumPy 1.26.4, which satisfies TensorFlow’s requirement, then install both packages in order:

pip install numpy==1.26.4
pip install tensorflow==2.16.2
pip install opencv-python

This works because OpenCV’s actual dependency is more flexible than what pip displays—the NumPy >=2 requirement only applies to newer Python environments, while TensorFlow strictly needs NumPy 1.x. By installing NumPy 1.26.4 first, pip respects the existing version when installing OpenCV, avoiding the conflict.

Alternatively, downgrade to an older OpenCV version compatible with NumPy 1.x, or upgrade to TensorFlow 2.17+ when released, which should support NumPy 2.x.

Try this and let me know if it works for you.

1 Like