Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install cv2?

My environment: Ubuntu 18.0.4 LTS (also tried on 19.04)

I use/need python3 (3.6.8 installed)

I need cv2, which is a model of opencv.

I tried several receipts I found on the Internet, but nothing worked.

I tried to install as pre-compiled (sudo apt-get install python-opencv) - No error, but when I try the test:

import cv2 as cv
print(cv.__version__)

I get error module not found.

The problem seems that I have installed also anaconda. The above test uses then anaconda, and cannot find the module.

Compiling from source installed for python2, but I do need python3. (The test also uses anaconda)

One of my receipts worked till the end, but with the line:

workon OpenCV-master-py3

It gaves me the error workon not found.

I tried then to install via Conda, but that wants to downgrade Conda.

Is there a way to run it without anaconda and find a replacement for "workon OpenCV-master-py3"

like image 771
Ronald Wiplinger Avatar asked Sep 11 '19 06:09

Ronald Wiplinger


People also ask

How do I add cv2 to Python?

Start the Python shell by typing python3 and then hit enter. You will be inside the Python shell where you can execute your Python code. Import the cv2 package which is the name of the OpenCV module. Type “import cv2” and hit enter.

How do I install Open cv2 on pip?

In order to build opencv-python in an unoptimized debug build, you need to side-step the normal process a bit. Install the packages scikit-build and numpy via pip. Run the command python setup.py bdist_wheel --build-type=Debug . Install the generated wheel file in the dist/ folder with pip install dist/wheelname.whl .

Is there cv2 module in Python?

cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python". The traditional OpenCV has many complicated steps involving building the module from scratch, which is unnecessary. I would recommend remaining with the opencv-python library.


1 Answers

For python3 you can simply do pip3 install opencv-python and it will work.

like image 175
The BrownBatman Avatar answered Nov 14 '22 17:11

The BrownBatman