Why cv2.so missing after opencv installed?

后端 未结 9 1265
你的背包
你的背包 2020-12-01 01:24

Today I installed opencv 2.4.4 to Ubuntu 12.10

But import cv2 not works.

root@-:~# python
Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
[GCC 4.7.2]          


        
相关标签:
9条回答
  • 2020-12-01 02:23

    How to install opencv(cv2) with python bindings in Linux - Ubuntu/Fedora

    1. Install gcc, g++/gcc-c++, cmake (apt-get or yum, in case of yum use gcc-c++)

      apt-get install gcc, g++, cmake
      
    2. Downlaod latest opencv from openCV's website

    3. Untar it with

      tar -xvf opencv-*
      
    4. Inside the untarred folder make a new folder called release

      mkdir release
      cd release
      

      (or any folder name) and run this command in it

      cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..
      

      the .. will pull files from the parents folder and will get the system ready for installation on your platform.

    5. in the release folder run

      make
      
    6. After about 2-3 mins of make processing when its finished run

      sudo make install
      
    7. Export python path

      export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
      

    That's it, now go to python and try

    >>> import cv2
    

    you should not get any error message.

    Tested on python 2.7, should be virtually similar to python 3.x.

    0 讨论(0)
  • 2020-12-01 02:24

    All above answers did not work for me, however, after a whole day struggling, I finally solved this problem.

    To have cv2.so, we need:

    1. At least python 2 or 3 installed. that why people say: sudo apt-get install python-dev. But that's not necessary, in my case, I use anaconda python. (there are many ways to install python)
    2. numpy is also a must. so, whatever python you use, just make sure you have it downloaded. In my case, I use anaconda numpy. (anaconda have it installed already, for normal python, use pip install numpy)

    To tell camke where the path is, just take my command as an example:

    cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
          -D PYTHON2_EXECUTABLE='/home/parallels/anaconda2/bin/python' \
          -D PYTHON2_LIBRARY='/home/parallels/anaconda2/lib/python2.7' \
          -D PYTHON2_NUMPY_INCLUDE_DIRS='/home/parallels/anaconda2/lib/python2.7/site-packages/numpy/core/include' \
          -D BUILD_EXAMPLES=ON ..
    

    for python3,you should (I'm using anaconda python, so I linked everything to anaconda):

    cmake -D CMAKE_BUILD_TYPE=Release \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.3.1/modules \
          -D PYTHON3_EXECUTABLE='/home/test/SoftWare/anaconda3/bin/python3.6m' \
          -D PYTHON_INCLUDE_DIR='/home/test/SoftWare/anaconda3/include/python3.6m' \
          -D PYTHON3_LIBRARY='/home/test/SoftWare/anaconda3/lib/libpython3.6m.so' \
          -D PYTHON3_NUMPY_INCLUDE_DIRS='/home/test/SoftWare/anaconda3/lib/python3.6/site-packages/numpy/core/include' \
          -D PYTHON3_PACKAGES_PATH='/home/test/SoftWare/anaconda3/lib/python3.6/site-packages' ..
    

    One thing to remember!!! before you enter cmake ... 1. clean your build folder, 2. Only camke once! otherwise you can not change ** PYTHON3_LIBRARY: NO**...(this is a bug I think)

    I know there might be some useless arguments, but I am tired to try to clean them. Here's a screenshot of my cmake print info. screenshot of my cmake info

    You can clearly see that, only python2 can generate cv2.so. python3 can not! (Python3 wrappers can not be generated).

    0 讨论(0)
  • 2020-12-01 02:26

    None of the above worked for me; am in Ubuntu 16.04 on an ec2 instance & had anaconda installed so I just used

    conda install opencv for both my conda2 and 3 installs

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