pytest-dev / pytest-dev/pytest
ImportError with cv2 (opencv)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported difference between direct import cv2 and running under pytest 6.2.2 with Python 3.9, conda, and Windows; compare it with the stated Linux setup. The issue provides no repository file or test to modify, so done means identifying the cause and documenting a reproducible diagnosis or a clearly scoped fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- opencv, python
- Domain
- operating-systems, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100