How to Fix Errors encountered in executing Python scripts with command line parameters

Today, when I was learning to execute a Python script with command line parameters, there was an error
ModuleNotFoundError: No module named ‘cv2’ at runtime. The problem has been solved, so I think I can write a note for your reference

import argparse
import cv2 as cv
import imutils
ap.add_argument('-i','--input',required=True,help='path to input image')
ap.add_argument('-o','--output',required=True,help='path to output image')

Then open the console and type

// An highlighted block
$ python --help

It did not get the result I wanted, so an error was returned, and cv2 (ModuleNotFoundError: No Module named ‘Cv2’) had to be found in the file. I think pycharm and the environment of this machine are independent. I tried to run OpenCV in Pycharm and did not report any mistakes, so they are independent. OpenCV is also installed in the native environment before it can be used.
first open our console
install OpenCV

again error, the yellow part is important information, tell us to upgrade our PIP to 20.2.3 version
upgrade PIP version

python -m pip install --upgrade pip

appears such a page is successfully upgraded
again install OpenCV

python -m pip install opencv-python

install imutils

python -m pip install imutils

ok, now let’s go to our script file and open the console and type:

python --help


Read More: