opencvpycharmdeepnote

Opencv not installing?


I've tried to install cv2 into deepnote and also into Pycharm using the following code - but nothing seems to work? Is cv2 not installable anymore? I've been using it up till last week and it was working fine but it doesn't seem to work anymore.

!pip install opencv-python
!pip install --upgrade pip

import cv2 # openCV for computer vision
import numpy as np # numpy for arrays
import pandas as pd
from matplotlib import pyplot as plt # matplotlib for plotting

Anyone have any idea what has happened? I've not changed any code whatsoever. Thanks


Solution

  • The linked code is correct. In some environments (like Deepnote), however, you have to install extra dependencies as suggested in this answer.

    !apt update
    !apt install ffmpeg libsm6 libxext6  -y
    

    Here's an example notebook of this working properly. Specifically in Deepnote, you can move the apt and pip install calls into a Custom environments Dockerfile.

    In the future, please be more specific about what is not working.