Python 3.10.2 bundled with blender has trouble loading cv2 module

Hi,

After updating to windows11 and blender3.3 LTS. I cannot run my opencv based blender scripts anymore. If I open the python execitable bundled with blender 3.3 and enter “import cv2” i get:
Importerror: dll load failed while importing cv2: the specified module could not be found.

But of I do help(“modules”) i see the module is there. Also pip uninstalling and installing the opencv-python package doesn’t help. Also investigating the dependencies of the site-packages\cv2\cv2.pyd doesn’t show any problems.

As a last step I installed a system wide python3.10.7 from python.org. That installation has no trouble importing the cv2 module. So next step for me was trying to convince blender to use this system wide python installation so i renamed the python folder in the blender 3.3 folder. But strangely blender is still somehow able to find the python version bundled woth blender (3.10.2). :frowning:

Can someone help me with this problem?

Thanx already very much.

Michiel

Though I am not exactly sure if this can help. But at least you can double check again just in case there is something to be noted.

As of now Blender still has the local python.exe
blender\3.3\python\bin\python.exe

The real motivation here is that in this way I can keep system python and blender python separate, each one into their own sandbox. If cv2 needs some specific older version for backwards compatibility then it might be the case as well.

Thanx for helping. It has indeed something to do with the difference between system wide pip site packages, user site packages and blender bundled pip site packages. But i don’t really understand what’s going on. After reading this link i tried the blender switch --python-use-system-env.

This magically resolved my problem.

Those security / dependency hell problems are so annoying…

Gr

Michiel

1 Like

If OpenCV is installed on your system but Python cannot find it, you will get the “no module named ‘cv2’” error message. This can happen if OpenCV is not in the Python path. The Python path is a list of directories where Python looks for modules and packages. You can check the Python path by running the following command in your terminal or command prompt:

python -c "import sys; print(sys.path)"

This will print out the directories in the Python path. Make sure that the directory where OpenCV is installed is included in the Python path.