How do I install opencv using pip?

后端 未结 18 689
情歌与酒
情歌与酒 2020-12-03 00:19

I need to install cv2 for a script that has been written for me. I tried pip install cv2 and pip install open_cv and got the same pro

相关标签:
18条回答
  • 2020-12-03 00:42

    In pip package management, there are 4 different OpenCV packages all using the same namespace, cv2. Although they are not officially supported by OpenCV.org, they are commonly used in developers' community. You could install any of them using the following command:

    pip install PACKAGE_NAME
    

    where PACKAGE_NAME can be

    • opencv-python (only contains main modules)
    • opencv-contrib-python (contains both main and contrib modules)
    • opencv-python-headless (same as opencv-python but without GUI functionality)
    • opencv-contrib-python-headless (same as opencv-contrib-python but without GUI functionality)

    You should only install one of them depending on your needs. If you accidentally installed multiple of them in the same environment, you can remove them using pip uninstall before installing the correct one again.

    For more details, you can refer to the project description of OpenCV on Wheels.

    0 讨论(0)
  • 2020-12-03 00:43

    run the following command by creating a virtual enviroment using python 3 and run

    pip3 install opencv-python
    

    to check it has installed correctly run

    python3 -c "import cv2"
    
    0 讨论(0)
  • 2020-12-03 00:43

    As a reference it might help someone... On Debian system I hard to do the following:

    apt-get install -y libsm6 libxext6 libxrender-dev
    pip3 install opencv-python
    python3 -c "import cv2"
    
    0 讨论(0)
  • 2020-12-03 00:45

    Make a virtual enviroment using python3

    virtualenv env_name --python="python3"
    

    and run the following command

    pip3 install opencv-python
    

    to check it has installed correctly run

    python3 -c "import cv2"
    
    0 讨论(0)
  • 2020-12-03 00:47

    As of 10/22/2019, I think the best answer is simply

    conda install opencv
    

    It appears opencv is now in the main Anaconda channel.

    To see which packages (including opencv) are in the main Anaconda channel go to Anaconda Package Lists and follow the link corresponding to your python version and os version.

    0 讨论(0)
  • 2020-12-03 00:47

    Simply use this for the so far latest version 4.1.0.

    pip install opencv-contrib-python==4.1.0.25
    

    For default version use this:

    pip install opencv-contrib-python
    

    For quick installation: https://youtu.be/iZKVFwez260

    0 讨论(0)
提交回复
热议问题