Intel® Distribution of OpenVINO™ Toolkit
Community support and discussions about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all things computer vision-related on Intel® platforms.
6025 Discussions

On Openvino 2021.R1 version can't import cv2

EddieChen
Novice
1,356 Views

As the title,

I'm using the openvino 2021.R1 version.

When I import the opencv to my own code, will report error.

Like this:

EddieChen_0-1605766693356.png

"ImportError: DLL load failed while importing cv2"

 

This situation is occurring to the Openvino environment initialized done.

If initialize done, the python can not be imported the Opencv.

 

But, I changed to Anaconda environment.

The python can imported openvino-opencv.

 
 
 
 

Like this:

擷取.PNG

 

Best regards,

0 Kudos
7 Replies
Maksim_S_Intel
Employee
1,343 Views

Looks like OpenVINO does not fully support Python 3.8 on Windows yet, because in this version PATH environment variable is not used to find DLLs when loading the module (see https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-python-api).

As a workaround try to manually call "os.add_dll_directory" with path to "<openvino>/opencv/bin". If it does not help try to call add_dll_directory for each of location which setupvars.bat script adds to the PATH variable (paths starting in <openvino> root).

Or use Python 3.7.

EddieChen
Novice
1,325 Views

Dear Maksim,

Thank you for your reply.

But, I don't understand.

I'm very confused, when using Anaconda to import opencv, this problem will be solved. 

 

Also, I'm trying your provide a method, manually call "os.add_dll_directory" this API.

It's seems not working,too.

 

The reason of I want to use python 3.8, is the memory shared are only supported python version>=3.8.

Maksim_S_Intel
Employee
1,313 Views

I'm very confused, when using Anaconda to import opencv, this problem will be solved. 

I believe conda python applies patches reverting mentioned behavior.

Also, I'm trying your provide a method, manually call "os.add_dll_directory" this API.

It's seems not working,too.

 I tried with python 3.8.6 from the official site and it worked for me, please check whether you used double backslash in paths:

os.add_dll_directory("C:\\openvino_2021.1\\deployment_tools\\ngraph\\lib")
os.add_dll_directory("C:\\openvino_2021.1\\deployment_tools\\inference_engine\\external\\tbb\\bin")
os.add_dll_directory("C:\\openvino_2021.1\\deployment_tools\\inference_engine\\bin\\intel64\\Release")
os.add_dll_directory("C:\\openvino_2021.1\\deployment_tools\\inference_engine\\external\\hddl\\bin")
os.add_dll_directory("C:\\openvino_2021.1\\opencv\\bin")

 

EddieChen
Novice
1,304 Views

Dear Maksim,

Thank you!

I'll try to add the other dll path, and test it!

 

Best regards,

Eddie

IntelSupport
Community Manager
1,321 Views

Hi EddieChen,

 

Thanks for reaching out.

This happened because Python 3.8 is not fully supported for OpenVINO 2021.1 toolkit yet. I would suggest you install Python 3.7 version.

Meanwhile, the reason you can import OpenCV when using Anaconda might be the installation of the OpenVINO toolkit from Anaconda Cloud is not specify the version of the Phyton.

 

Regards,

Aznie


EddieChen
Novice
1,309 Views

Dear Aznie,

Thank you a lot, I got it!

Wish upgrades openvino as soon as possible, which really powerful and convenient!

 

Best regards,

Eddie

IntelSupport
Community Manager
1,262 Views

Hi Eddie,

This thread will no longer be monitored since this issue has been resolved. If you need any additional information from Intel, please submit a new question.


Regards,

Aznie


Reply