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

1
  • I noticed that you have not accepted a single answer for any of your 20+ questions. May I ask why?
    – timgeb
    May 30, 2017 at 8:23

2 Answers 2

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

3
  • 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. Oct 3, 2013 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? Oct 3, 2013 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! Mar 8, 2017 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.