Search code examples
pythonopencvvirtualenvvirtualenvwrapper

Unable to import opencv in virtualenv


I have installed opencv successfully in my system and able to import it without virtualenv. I know I need to copy cv2.so files in my virtualenv directory to be able to use it within virtualenv, but the problem is there is NO cv2.so files in my local site packages. All I can see some .so files named with libopencv-core * alike.

I grep-ed it, tried finding it manually in site-packages, py-modules, but no clue why its isn't there?

I've successfully build and make all files, I am sure there is nothing missed while installing it, because without virtualenv I am easily executing it.

OpenCV Version: 2.4.8 Python Version: 2.7.8 OS: Ubuntu 14.01


Solution

  • To import opencv using your virtualenv you should install it on your virtualenv or copy the cv2.pyd (on windows) to your venv site-packages directory.

    If you are on linux you could install it using sudo apt-get install python-opencv.

    If you are building it from source you should follow the steps listed here. On step 12:

    Also make sure that in the PYTHON field, everything is filled. (Ignore PYTHON_DEBUG_LIBRARY).
    

    Look at the image presented in this step. The python paths listed there should be your venv python paths not your system's python paths.

    Hope it helps!