opencv install in virtual env trying to launch

4 posts / 0 new
Last post
opencv install in virtual env trying to launch


I have an issue to launch
File "", line 16, in
import cv2
ImportError: No module named cv2

I already have executed : sudo apt-get -y install libcv-dev libopencv-dev python-opencv

For my virtual env I have :

pip list
Package Version
----------------------------- -------
backports.functools-lru-cache 1.5
cycler 0.10.0
kiwisolver 1.0.1
matplotlib 2.2.3
numpy 1.15.3
pip 18.1
pyparsing 2.2.2
python-dateutil 2.7.5
pytz 2018.6
setuptools 40.5.0
six 1.11.0
subprocess32 3.5.3
wheel 0.32.2

when I executed pip install
pip install python-opencv
Looking in indexes:,
Collecting python-opencv
Could not find a version that satisfies the requirement python-opencv (from versions: )
No matching distribution found for python-opencv

My Python version for the virtual env Python 2.7.13

It seems that in my virtual env I don't have opencv.
Do you have an idea about that?

Thanks a lot,
Tri Duc

Arron Churchill
Arron Churchill's picture
This may help

I do not have a lot of experience with virtualenv, but I did come across these instructions after a quick web search:

Hopefully they will get you going :)

Thanks for your reply.

Thanks for your reply.

I manage to install opencv in my virtual env in following :

I had several errors when compiling, the following options are working for me

-D BUILD_opencv_ts=OFF \

jtobinart's picture
Why use a virtual environment?

Hi tdtran,

Adrian’s pyimagesearch blog can be a helpful resource but there are multiple reasons why you can get errors when using his tutorial. It is hard to say why you get any specific errors. A helpful place to start looking for answers is to search the comments section below the tutorial that Adrian wrote. You will find that readers have asked him many tiimes for help about error messages.

I see the guide you linked is for a Raspberry Pi. You don’t need to use a virtual environment. They can be helpful but are not necessary. Also, if you dedicate a microSD card to just the formulaPi race, it will accomplish the same thing on your Raspberry Pi.

Adrian also has other helpful guildes specifically designed to help you install openCV on macOS and Ubuntu. Check them out! If you are using a Mac, he has a quick and easy tutorial for using homebrew to install openCV.

As for your first post, make sure that you create a symbolic link or reinstall the packages from within your virtual environment. Checkout Adrian’s tutorials about how to set up a symbolic link.

Adrian pushes for the use of virtual environments in his tutorials. But, virtual environments are a personal choice and I personally don’t use virtual environments on my Pi. I have used them on my Mac, but not for Formula Pi. If you are just starting out, it would be easier to skip them for now. You can always start using them in the future.

Best of luck,

Sheldon’s Fury

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: bash, cpp, perl, python.
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Comment Images
Files must be less than 10 MB.
Allowed file types: png gif jpg jpeg.
Comment Attachments
Files must be less than 10 MB.
Allowed file types: txt pdf nfo doc docx rtf jpg png gif bmp zip tar gz csv xls.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.