Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can OpenCV be installed in python virtualenv on Mac Mountain Lion

I have install Numpy and Scipy with virtualenv on my mac.

Today, I want to installed Opencv under virtualenv. I try:

pip install pyopencv

the terminal returned:

Could not find a version that satisfies the requirement pyopencv (from versions: 2.0.wr1.0.1-demo, 2.0.wr1.0.1, 2.0.wr1.1.0, 2.1.0.wr1.0.0, 2.1.0.wr1.0.1, 2.1.0.wr1.0.2, 2.1.0.wr1.1.0, 2.1.0.wr1.2.0, 2.1.0.wr1.2.0-demo, 2.1.0.wr1.2.0) Cleaning up... No distributions matching the version for pyopencv

like image 450
user2262504 Avatar asked Dec 08 '22 12:12

user2262504


2 Answers

I had the same problem, I couldn't get OpenCV installed in virtualenv using pip in the proper way. However this is what I have done:

  1. Install OpenCV and Python using Homebrew (and all depenencies such as numpy)
  2. Then I installed virtualenv and create a new virtual environment with numpy.
  3. Finally what I did was symlinked the folder from the "normal" python installation to the virtualenv:

    $ ln -s /usr/local/lib/python2.7/site-packages/cv2.so /usr/local/lib/python2.7/site-packages/cv.py ~/envs/lib/python2.7/site-packages
    

So when I launch the virtualenv I have cv2 available:

(virtualenv)localhost:~ juan$ python
Python 2.7.3 (default, Mar 18 2013, 11:14:52) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2
<module 'cv2' from '/Users/juan/envs/lib/python2.7/site-packages/cv2.so'>

By the way I am using Python 2.7.3, OpenCV 2.4.4a, virtualenv 1.10.1 on MacOSX 10.8.5

like image 119
jabaldonedo Avatar answered Dec 31 '22 14:12

jabaldonedo


I followed parts of this tutorial to setup opencv in virtualenv.

The cumbersome part is that everytime i create a virtual env, i need to copy opencv to the lib folder. But hey, it works!

In a nutshell..

$ brew install python
$ pip install numpy
$ brew install opencv

$ cp /usr/local/lib/python2.7/site-packages/cv* <path-to-venv>/lib/python2.7/site-packages

<path-to-venv> is the path where you have created your virtual env.

Hope this helps.

like image 21
srik Avatar answered Dec 31 '22 13:12

srik