Python cv2 opencv-python opencv-contrib-python installation

As the old rule goes, don’t talk too much, just code!

pip install opencv-python (if only the main module is used, use this command to install [recommended])

pip install opencv-contrib-python (If you need to use the contrib module, use this command [I didn’t try it this time because I didn’t use the contrib module])

First of all, let me tell you that the cv2 module is opencv, so opencv-python is used when installing. After installation, find the directory where the third-party library is installed. You can see the cv2 module and opencv_python-4.6.0.66.dist-info containing version information (the version I downloaded and installed this time, you will correspond to your own version when the time comes. (can) directory. When writing code, just import cv2 directly (there is no code hint for calling this module in pycharm!!!).

Secondly, when using the command line to download opencv-python, you will find that the download speed is very slow (about 20KB/s), and the installation package is relatively large (about 35MB), so here is a solution, which I use. You can go directly to the official website ( https://pypi.org/project/opencv-python/ ) to download the corresponding version of the whl file (because the browser can switch the mirror address when downloading, the download speed will be very fast later) , it will take a few minutes to finish downloading. It doesn’t matter if it’s slow at first, but it’ll be fast later).

Again, for those who have never been exposed to whl files (if you understand, just skip this paragraph), here is an explanation, whl file: This file is essentially a compressed package, which contains py files and compiled pyd files. . In fact, if you pay attention, you will find that all such files are downloaded during pip installation.

Then, before installing the whl file, you need to install wheel (because wheel is used to install whl files). Just use pip install wheel to install it. This installation has no dependencies, and the installation package is very small (about 0.35MB), so install soon. After installing wheel, go to the directory where you downloaded and saved the whl file, use pip install opencv_python-4.6.0.66-cp36-abi3-win_amd64.whl (replace it with your own file and version), and the installation is OK. (Installing this library requires the installation of a dependency on numpy, so it will be downloaded on the command line. It will also take some time to download the numpy installation package. If you don’t want to wait for the same method, you can do it. You don’t need to rely on it to install numpy, but you need to pay attention to the version. I This version of opencv-python requires numpy>=1.17, so it is recommended to wait, so you don’t have to toss yourself)

Guess you like

Origin blog.csdn.net/m0_74060105/article/details/128501402