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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…