0

I have minconda3 and python 3.8. I have been trying to install opencv through various ways and it is still not working. I used:

pip install opencv
pip install opencv-python
conda install py-opencv

I tried installing using wheel but couldn't find a version that satisfied. I keep getting this error:

dll load failed while importing cv2: The specified module could not be found.
CypherX
  • 7,019
  • 3
  • 25
  • 37
Fatima Arshad
  • 119
  • 1
  • 9
  • Have you tried this? https://stackoverflow.com/questions/43184887/dll-load-failed-error-when-importing-cv2 – Ananda Jan 29 '21 at 10:11

1 Answers1

0

Solution: OpenCV installation for Python using conda Super Easy ✨

Try creating a new environment first. If you are using conda, it is better to use conda install whenever possible over pip install. You need to specify the channel conda-forge for opencv (it has the most updated version on conda).

The following command should do it.

conda create -n opencv_env python=3.8 -c conda-forge opencv numpy matplotlib scipy

Once installed, activate the environment with conda activate opencv_env.

However, for reproducibility, I would encourage you to create an environment.yml file and create/update the environment easily whenever necessary. See here for more details on it.

Save the following as environment.yml file. And then run conda env create -f environment.yml from the same location as the environment.yml file.

### filename: environment.yml
#
### To create environment run:
#   conda env create -f environment.yml
#
### To update environment run:
#   conda env update -f environment.yml --prune
#
### Note: 
# The --prune option causes conda to remove any 
# dependencies that are no longer required from 
# the environment.
#
### Activating the environment
#   conda activate opencv_env
#
### Deactivating the environment
#   conda deactivate opencv_env


name: opencv_env # <-- The name of the environment
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.8
  - opencv # -c conda-forge
  - numpy
  - matplotlib
  - scipy
  - pip:
    # list packages for which "pip install <package>" is necessary
    #- hypothesis

References

CypherX
  • 7,019
  • 3
  • 25
  • 37