4

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

jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
user2262504
  • 7,057
  • 5
  • 18
  • 23
  • I noticed that you have not accepted a single answer for any of your 20+ questions. May I ask why? – timgeb May 30 '17 at 08:23

2 Answers2

11

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

kahbou
  • 128
  • 4
jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
  • The symbolic link works. But here the parameters after -s is "ln -s file link". Thank you for your answer. Can you explain more. I am really new to Mac. – user2262504 Oct 03 '13 at 12:08
  • 1
    It quite simple, what you are doing is using the opencv installed by your normal python in the virtualenv. what exactly do you want I explain? – jabaldonedo Oct 03 '13 at 14:04
  • Elegant and doesn't waste space like the solution where you have to copy the cv.py and cv2.so files. Thanks for the help! – VanGoghsCoffee Mar 08 '17 at 20:00
3

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.

srik
  • 1,447
  • 2
  • 20
  • 33