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=argparse.ArgumentParser()
ap.add_argument('-i','--input',required=True,help='path to input image')
ap.add_argument('-o','--output',required=True,help='path to output image')
args=vars(ap.parse_args())
Then open the console and type
// An highlighted block
$ python shape_counter.py --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
command:
python -m pip install --upgrade pip
appears such a page is successfully upgraded
again install OpenCV
command:
python -m pip install opencv-python
install imutils
command:
python -m pip install imutils
ok, now let’s go to our script file and open the console and type:
python shape_counter.py --help
Results:
Read More:
- How does Python output colored fonts in the CMD command line window
- Pychar can’t connect to Python console, but it can run. Py file, and Anaconda’s command line can run Python command
- How to Fix keyerror in Python dictionary lookup
- How to Fix “HTTP error 403: forbidden” in Python 3. X
- Python: How to Set Line breaks and tabs for Strings
- How to Fix pandas.errors.ParserError Error tokenizing data C error Buffer overflow caught
- ModuleNotFoundError: No module named ‘tensorflow.python’ And the pits encountered after installation
- How to Fix Python reading large local file memory error
- Opencv Python realizes the paint filling function in PS, one click filling color and the possible reasons for opencv’s frequent errors
- An introduction to sys modules in Python and how packages are imported and used
- [Solved] VScode Configurate Python Interpreter Error: D:\Pros\virtuals\venvs\Scripts\Activate.ps1 cannot be loaded
- Python custom convolution kernel weight parameters
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Python+OpenCV: How to Use Background Subtraction Methods
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- When sending HTTP request, python encountered: error 54, ‘connection reset by peer’ solution
- [Solved] Ubuntu18.04 Install pyqt5 error: Command “python setup.py egg_info“ failed with error code 1 in /tmp/pip-build-92
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- Python uses try… Except… To output detailed errors
- [Solved] error indicates that your module has parameters that were not used in producing loss