8

I need to use opencv in a project that is in a virtual environment, but you cannot install opencv with pip.

installing on my local machine (OSX Yosemite, version 10.10.1) with homebrew works just fine, but I cannot do "brew install" in my virtualenv.

How can I include opencv in my environment?

Ryan Saxe
  • 16,019
  • 22
  • 75
  • 123
  • Do you want to install OpenCV only in virtualenv or just make OpenCV work in virtualenv? – yangjie Jul 13 '15 at 17:33
  • Ideally I would want it in the virtualenv so that others can copy my identical environment. – Ryan Saxe Jul 13 '15 at 17:37
  • I've been looking around on the web and I found this [blog post](http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/). Hope it helps! – tenfishsticks Aug 18 '15 at 21:15

3 Answers3

3

As described here (see Option B) you can run this from inside your virtual environment:

pip install opencv-contrib-python

As mentioned at that link, opencv-contrib-python is an unofficial pre-built OpenCV package.

I tested this on Linux.

packoman
  • 1,087
  • 11
  • 32
1

I use Windows 10. In my case, in order to use openCV in my new virtual environment, I manually copied all of the files regarding openCV which are in C:\Program Files (x86)\python36\Lib\site-packages to virtual environment directory C:\Program Files (x86)\ibrahim\Lib\site-packages. Then, import cv2 to python and it worked for me. Be noted that you need to copy all of the files inside red boxes that I showed below.

**Files inside red boxes to be deleted**

Khin Maung Htay
  • 181
  • 1
  • 5
0

For OpenCV 2, try this.

Basically, install Python bindings for OpenCV 2 system-wide, then copy the library file into your virtual environment.

Velimir Mlaker
  • 10,151
  • 4
  • 43
  • 55