Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV and python/virtualenv?

I'm working on a project in python that uses OpenCV (2.3.1), among other libraries. So far, I just apt-get installed everything, but now I want to share my code with someone that might not have everything installed already. So, virtualenv seems like the perfect solution, but I get this.

$ python src/importcv.py # does nothing but import cv, no problems
$ virtualenv .           # create virtualenv here
$ source bin/activate    # activates this virtualenv
(p)$ python src/importcv.py
Traceback (most recent call last):
  File "src/test.py", line 1, in <module>
    import cv
ImportError: No module named cv

Was there something wrong in how I set up the virtualenv, or do I have to do some other step so it can see my opencv python bindings?

like image 887
Nate Parsons Avatar asked Nov 09 '12 16:11

Nate Parsons


People also ask

Can you pip install OpenCV?

OpenCV can be installed using pip.

Can OpenCV run on Raspberry Pi?

OpenCV makes adding computer vision to your Raspberry Pi projects a straight-forward process. Using it, you could train the Raspberry Pi to classify or recognise objects and react to them.

Why use virtual environment python?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects.


1 Answers

Simply copy of the cv2*.so file to the site-packages folder of the virtual environment. For example:

cp /usr/lib/python3.6/dist-packages/cv2.cpython-36m-aarch64-linux-gnu.so ~/your_virt_env_folder/YOUR_VIRT_ENV_NAME/lib/python3.6/site-packages/
like image 143
B.Kocis Avatar answered Oct 04 '22 21:10

B.Kocis