question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError with cv2 (opencv)

See original GitHub issue

Hi!

This something I noticed with Python 3.9 / pytest-6.2.2 / conda / Windows: while import cv2 works on Python, it causes an ImportError (dll not found) when testing my code with pytest. I use various libraries like numpy, sklearn… and cv2 is the only one causing such error. It’s also the only one being installed as a single .pyd file put directly into the site-packages folder. The other one have their own folders.

import cv2
import sklearn
import numpy
print(cv2.__file__)
>>> C:\Users\francois\Miniconda3\envs\standard\lib\site-packages\cv2.cp39-win_amd64.pyd
print(sklearn.__file__)
>>> C:\Users\francois\Miniconda3\envs\standard\lib\site-packages\sklearn\__init__.py
print(numpy.__file__)
>>> C:\Users\francois\Miniconda3\envs\standard\lib\site-packages\numpy\__init__.py

Note that this problem does not exist on Linux (same Python 3.9 / pytest-6.2.2 / conda). In this case cv2 is also installed as a single file into the site-packages folder, but this time with a the .so extension.

Is there something I can to do fix it or at least give more useful information?

EDIT: added the code showing the difference between cv2 and sklearn/numpy.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
RonnyPfannschmidtcommented, Mar 4, 2021

We might have to keep it open as to ensure pytest import strategy won’t break stuff

0reactions
FrankwaPcommented, Mar 10, 2022

@Xsavaga25282 Did you read the comments in this thread?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module cv2 when using OpenCV
First do run these commands inside Terminal/CMD: conda update anaconda-navigator conda update navigator-updater.
Read more >
cannot import name '_registerMatType' from 'cv2. ...
Trying to import cv2 in python 3.9.2 gives me the following error: File "C:\Users\My ...
Read more >
ERROR: recursion is detected during loading of "cv2 ...
Check OpenCV installation.') ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
Read more >
Error importing cv2 after compiling OpenCV from source ...
If it is not there then you haven't built the bindings and you won't be able to call your build from python. I...
Read more >
Cannot import name '_registerMatType' from 'cv2.cv2'
The "ImportError: cannot import name '_registerMatType' from 'cv2.cv2'" occurs due to incompatibility of versions of the opencv-* packages. To ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found