OpenCV Python No module named 'cv2'

asked 2020-03-28 08:29:16 -0600

andrei186 gravatar image

updated 2020-03-29 05:22:38 -0600

I've got installed and running OpenCV with C++. Tried to test it with Python3, but

    workon dl4cv
    import cv2


     ModuleNotFoundError: No module named 'cv2'

My environment is Ubuntu 18.4, OpenCV 3.4.10 , Python 3.6.9

People on stackexchange suggest various manipulation with .profile and pathes without explaining why, but without understanding I feel uncomfortable performing such shaman tambourine dances over system parameters.

Could some oneexplain or give links to the resources, explaining how this is working and how to fix it if is does not work?

edit retag flag offensive close merge delete



Did you install python-opencv? Just OpenCV is not enough.

mvuori gravatar imagemvuori ( 2020-03-29 02:30:48 -0600 )edit

I installed OpenCV using Install OpenCV 4 on Ubuntu 18.04 (C++ and Python) .

It does not have an explicit line install python-opencv, yet it has Python-related sections Step 3: Install Python Libraries:

sudo apt -y install python3-dev python3-pip
sudo -H pip3 install -U pip numpy
sudo apt -y install python3-testresources
cd $cwd
 # create virt envir

python3 -m venv OpenCV-"$cvVersion"-py3
echo "# Virtual Environment Wrapper" >> ~/.bashrc
echo "alias workoncv-$cvVersion=\"source $cwd/OpenCV-$cvVersion-py3/bin/activate\"" >> ~/.bashrc
source "$cwd"/OpenCV-"$cvVersion"-py3/bin/activate

now install python libraries with

pip install wheel numpyscipymatplotlibscikit-imagescikit-imagescikit-learn ipython dli

andrei186 gravatar imageandrei186 ( 2020-03-29 04:11:06 -0600 )edit

Sorry, every time I struggle formatting my comments and still it looks like mess. It ignores line breaks, preformatted text for code has its own agenda and now one line for some reason is shown in large letters

andrei186 gravatar imageandrei186 ( 2020-03-29 04:34:47 -0600 )edit

need to add that in /home/a/.virtualenvs/dl4cv/lib/python3.6/site-packages/ i have The link you provided reads that python-opencv is just one way to install OpenCV using from Pre-built Binaries . Another one is Building OpenCV from source. This is how I did.

Do I still need to install python-opencv or perhaps I need just to help it to locate ?

andrei186 gravatar imageandrei186 ( 2020-03-29 04:42:01 -0600 )edit