Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install opencv into a virtual environment

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?

like image 621
Ryan Saxe Avatar asked Jul 13 '15 17:07

Ryan Saxe


People also ask

Can we install python in virtual environment?

As long as your virtual environment is active, python and pip link to the same executable files that python3 and pip3 do. Congratulations, you can now install your packages to your virtual environment.

Can you pip install OpenCV?

OpenCV can be installed using pip.


2 Answers

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.

like image 187
packoman Avatar answered Oct 07 '22 20:10

packoman


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**

like image 24
Khin Maung Htay Avatar answered Oct 07 '22 20:10

Khin Maung Htay