lnhubbell
lnhubbell

Reputation: 3395

Installing OpenCV, No module named cv2.cv

I am trying to follow the instructions found here for python.

Step 1 seemed to work, here are the last 5 lines from my terminal after I ran opencv.sh:

h.h  
./opencv.sh: line 16: cmake: command not found
make: *** No targets specified and no makefile found.  Stop.
sudo: checkinstall: command not found
OpenCV 2.4.9 ready to be used

However, when I moved on to step 2 I got the following error when running the python file from the command line:

Traceback (most recent call last):
  File "opencvFirst.py", line 4, in '<'module'>'
    from cv2.cv import *
ImportError: No module named cv2.cv

This doesn't seem to be my issue, because I can't find cv2.anything located on my computer, which is most likely part of the problem, but I don't know why step 1 wouldn't have installed it.

I think that this question is a little closer to what I need, but since I already completed step 1, as I said above, I'm not sure where to start with these separate instructions. I tried import cv2 but got an import error: no module cv2.

I'm very new to ubuntu, python, and all this command line stuff, thank you for your help!

Oh also, I should say: my final goal here is just to get OpenCV working, so if there is an easier/better way to do so, I am very open to suggestions.

Upvotes: 3

Views: 14611

Answers (3)

Ozzie
Ozzie

Reputation: 11

Here is the AWS (Linux) solution if you are receiving the following error: "ImportError: No module named cv2"

First make sure to install openCV with ASW Sagemaker Jupiter (Linux and use kernel=tensorflow_p36 as example)

  1. At the main AWS sagemaker terminal, open new Jupyter notebook where new is selected as a Terminal. This will open the command prompt vs. a regular Jupyter-notebook.
  2. At terminal command line enter the following commands to activate env first and then install opencv

conda environments (to see and digest what env you have. These are also kernels in you J-notebook).

source activate tensorflow_p36 (This is an example to use Python 3.6. your command line should change to (tf_p36))

pip install --upgrade pip    (in case your pip is not latest version)

pip install opencv-python   (this hopefully installs the openCV)
  1. go back to the regular jupyter window, change kernel to above and compile the code!

Upvotes: 0

Wei Yang
Wei Yang

Reputation: 199

By installing python-opencv package you should be able to solve the problem

sudo apt-get install python-opencv

Upvotes: 1

julienc
julienc

Reputation: 20355

Are you sure the installation worked properly? Because all I see during your first step is:

cmake: command not found
checkinstall: command not found

So maybe you should check that both cmake and checkinstall are installed, or install them if they are not before retrying the opencv.sh command:

sudo apt-get install cmake checkinstall
sudo ./opencv.sh

Upvotes: 1

Related Questions