Can't import OpenCV for Python

python

#1

I’ve tried various methods and can’t manage to use opencv in python.
I’m unable to install it using easy_install or pip.
I am able to install it using miniconda, but I’m then unable to use ‘import cv2’ in .py files that I’m working on by clicking ‘Run’.
However, if I enter python at the command line I can import cv2, but I want to be able to use the c9 editor and click Run.

Apologies if this is a noob question.

Can anyone me how to get opencv accessible to python scripts when I click Run?


#2

what command did you try for installing with pip?


#3

Not sure if this will work on c9, but on an VM running Ubuntu 16 I was able to install and run OpenCV 3 by following these instructions.

What is the error message that you get when you try to click “Run”?


#4

Idk if this helps but i’ve noticed when you click run, your application will run with the default python thats in the workspace which i believe is 2.7. If you are working with 3.6 (which i believe miniconda does) you might have to explicitly reference the python version from the command line and run your file.


#5

The commands I tried were sudo pip install opencv and sudo pip install opencv-python, both of which gave me:

Could not find any downloads that satisfy the requirement opencv
(or opencv-python)


#6

I’ve tried building opencv using https://github.com/jayrambhia/Install-OpenCV but run out of the 2GB free C9 disk space.

I simple get the

ImportError: No module named cv2


#7

I had a feeling it could have something to do with multiple installations of Python. But I have tried installing miniconda2 and miniconda3 both having the same outcome.

I can run python from the command line and import opencv, but I don’t understand how I it can be the same version with different modules availability.

Is it possible to change the instance than runs when I click the run button?


#8

Did you try installing OpenCV using the instructions I posted earlier? (http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/).

I’ll create a c9 workspace of my own and see if I can install OpenCV successfully.

Like what Arcrunner819 said earlier, it could be that when you click run, the wrong version of python could be running, which would mean that you would get the ImportError you described earlier. I believe c9 has documentation on how to change the command (i.e., which version of python) runs when you click the Run button here.


#9

I’ve tried following the steps, but arrive at a

Configuring incomplete, errors occurred!

I’m not sure how to fix this as I’ve never built something from source before, but I would following this through effectively achieve the same as this? I’ve tried the jayrambhia script before but C9 runs out of memory.

I’ve now figured out how to switch the run button between python 2&3. But even after switching between the two I can’t import cv2. Is it possible that I’ve installed a third instance of python through miniconda in another location somewhere that I could launch when clicking run?


#10

I’ve had the same issue and am on premium.


#11

I think I had this working but took so many stackoverflow visits in solving it, I can’t remember what I did exactly. But I had to search for ‘ubuntu’ in reference to the exact error, mine was something about how the program cannot find the cv2 module. I think I checked the version of Python I had, then searched for opencv there is a package needed for opencv + Python necessary for this. And all of that was when I had already installed Anaconda (which should update your Python). But as you know, 2GB for free workspace with Anaconda is not going to work - it’s gonna take up a bunch of space. Wish I could help more. - Julia


#12

TL;DR: Disk space is probably the problem

From this, under “Step #4: Configuring and compiling OpenCV on Ubuntu 16.04”, if the make build fails, it could be because of race conditions that occur when using multiple processors. Now, I don’t know if each c9 workspace has multiple processors, so that might not be the problem. But, I think it would be worth a try following the instructions provided (running make clean and then make) just to see if that works.

If it doesn’t, then it could be that the c9 workspace you’re using just doesn’t have enough disk space (as others have mentioned earlier). In that case, you’d be better off upgrading or use something other than c9, such as a regular computer. This is what happened when I tried to install OpenCV on one of my own c9 workspaces, so it seems likely that the 2GB c9 provides by default isn’t enough for OpenCV.