Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

python - unable to import opencv

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.
question from:https://stackoverflow.com/questions/65952352/unable-to-import-opencv

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...