''no module named cv2' import error on pytorch

I am currently studying Pytorch and trying to use the cv2 module. I am using Jupyter notebook and Windows.

I have installed opencv like this:

!pip install opencv-python

When I choose the kernel (by change kernel option) Python3 and import cv2 then there is no problem.

But when I choose the kernel Pytorch and import cv2, then there is an error:

ModuleNotFoundError: No module named 'cv2'

This must be a basic question but I can't find out what the problem is.



Solution 1:[1]

I found the answer to this problem here:

First do run these commands

$ conda update anaconda-navigator

$ conda update navigator-updater

then the issue for the instruction below will be resolved

For windows if you have anaconda installed, you can simply do:

pip install opencv-python

or

conda install -c https://conda.binstar.org/menpo opencv

If you're on linux you can do :

pip install opencv-python

or

conda install opencv 

Solution 2:[2]

If you run pip install opencv failed. You can download the whl file in here and then install it locally:

pip install opencv_python-4.5.5.64-cp36-abi3-win_amd64.whl

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jab
Solution 2 ?????