Is it possible to run opencv (python binding) from a virtualenv?

前端 未结 4 1269
悲哀的现实
悲哀的现实 2020-12-05 02:45

I would like to keep everything contained within the virtualenv. Is this possible with OpenCV? I\'m fine with building from scratch, do I just need to setup the virtualenv

相关标签:
4条回答
  • 2020-12-05 03:01

    I found the solution was that I had to copy over cv2.so and cv.py to the directory running the virtualenv, then pip install numpy. To do this on Ubuntu 12.04 I used.

    virtualenv virtopencv
    cd virtopencv
    cp /usr/local/lib/python2.7/dist-packages/cv* ./lib/python2.7/site-packages/
    ./bin/pip install numpy
    source bin/activate
    python
    import cv
    
    0 讨论(0)
  • 2020-12-05 03:02

    On Debian, I apt installed python-opencv, python-virtualenv, python-pip and then created a virtualenv using the option --system-site-packages.

    0 讨论(0)
  • 2020-12-05 03:03

    From opencv install guide :

    By default the OpenCV build system will choose the most recent version of Python that it can find, or you can force it to use a specific version using the PYTHON_EXECUTABLE variable when you invoke cmake.)

    I just installed it on my ubuntu 11.10, on virtual env --with-no-site-package, by following the instruction on the link above. you need to build whole opencv. and its python wrapper together.

    EDIT 1:

    1. Create a temporary directory, which we denote as , where you want to put the generated Makefiles, project files as well the object files and output binaries.

      cd ~/opencv
      mkdir release
      cd release
      cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
      
    2. Enter the created temporary directory () and proceed with:

      make
      sudo make install
      

    ---------

    after build & install add the extension modules on PYTHON_PATH

    export PYTHONPATH=~/projects/opencv/release/lib:$PYTHONPATH
    
    0 讨论(0)
  • 2020-12-05 03:05

    This is possible by passing the python executable as an argument to cmake. I would also suggest then to use a local install folder, so you don't need sudo at all. And then, if make install doesn't ask you for sudo permissions, it is probably targetting your virtualenv python .

    Open cmakelists.txt with cmake-gui to see the python variables. It would also probably give an error if you don't have numpy in your virtualenv, so that way you know it's choosing the right python. This would also work with independent of python version, as it is built specifically for your python executable

    0 讨论(0)
提交回复
热议问题