'Error when importing cv2 on anaconda prompt but it is working on jupyter notebook

I am importing libraries that I installed using pip install to Jupyter Notebook using the anaconda distribution, which is working. Next, I am trying to import the same libraries in the anaconda command prompt and running it. I am getting this error message:

ModuleNotFoundError: No module named 'cv2'



Solution 1:[1]

try these things:

  1. First check if you are able to see your library by this command: $ pip list or conda list

  2. if not available install this module: $ pip install opencv-python or conda install opencv-python

  3. But before that, try to check numpy module is available or not. If numpy is not available, then install this first. $ pip install numpy

  4. If all of them exist then, Uninstall opencv-python and numpy first and upgrade your pip using the below command. $ pip install --upgrade pip

Solution 2:[2]

Two options to install cv2 with the latest conda & python3:

  1. Open the Anaconda Prompt and switch to your environment:
    $ conda activate myenv
    Then install opencv from the menpo channel:
    $ conda install -c menpo opencv

  2. Open the Anaconda Prompt with admin permission and make sure you're in the base environment: $ conda activate base
    Then install opencv from the menpo channel:
    $ conda install -c menpo opencv

Reconnect your notebook to the kernel to import cv2.

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 Anant Arun
Solution 2