Installing opencv 3.1 with anaconda python3?

后端 未结 7 1124
温柔的废话
温柔的废话 2020-12-01 03:54

How do I install opencv with anaconda python3 , opencv picked up my python3 executables

--   Python 2:
--     Interpreter:                 /usr/bin/python2.7         


        
相关标签:
7条回答
  • 2020-12-01 04:10

    I think you don't need to build OpenCV for anaconda, there is this very handy tool called 'conda' that is available in your terminal once you have installed the Anaconda python distribution.

    I found this site which gives instruction on how to install opencv3

    https://anaconda.org/menpo/opencv3
    

    I personally installed it myself so just try follow along with these instructions.

    If you have the Anaconda python distribution installed in your system, you can issue this command (assuming you are working on linux) fire up the terminal:

    conda install -c menpo opencv
    

    If the version of python install in your Anaconda is 2.7, the command above should install OpenCV 3.1, but if the version of your python is 3.5, then you should change 'opencv' in the last line to 'opencv3'

    conda install -c menpo opencv3
    

    This should install OpenCV in your Anaconda. To see if you have installed it successfully, fire up your Python and issue the following command:

    import cv2 # import the opencv library
    
    cv2.__version__ # this will print the version of your opencv3
    

    Hope that helps =)

    0 讨论(0)
  • 2020-12-01 04:12

    Try this method it worked for me. Anaconda3-4

    conda create -n opencv 
    activate opencv
    conda install -c https://conda.binstar.org/menpo opencv3
    
    0 讨论(0)
  • 2020-12-01 04:15

    With conda v4.3.16 and python v3.6 this command worked for me:

    conda install -c anaconda opencv
    
    0 讨论(0)
  • 2020-12-01 04:17

    If you want to compile opencv against a specific anaconda environment, you can specify the PYTHON_EXECUTABLE, PYTHON_INCLUDE and PYTHON_LIBRARY, PYTHON_PACKAGES_PATH, PYTHON_NUMPY_INCLUDE_DIR variables in cmake.

    In the following example I have an opencv340 anaconda environment located in /home/yourself/anaconda3/envs/opencv340 and so I'll specifiy the above variables for cmake as follows:

    -DPYTHON_EXECUTABLE=/home/yourself/anaconda3/envs/opencv340/bin/python3 \
    -DPYTHON_INCLUDE=/home/yourself/anaconda3/envs/opencv340/include \
    -DPYTHON_LIBRARY=/home/yourself/anaconda3/envs/opencv340/lib/libpython3.6m.so \
    -DPYTHON_PACKAGES_PATH=/home/yourself/anaconda3/envs/opencv340/lib/python3.6/site-packages \
    -DPYTHON_NUMPY_INCLUDE_DIR=/home/yourself/anaconda3/envs/opencv340/lib/python3.6/site-packages/core/include
    

    You'll then see that opencv pick the correct python, the one in the anaconda environment of which you gave the path of.

    You then copy the cv2*.so from your opencv build directory to the site-packages of your anaconda environment.

    Your site-packages directory should be located somewhere like:

    /home/yourself/anaconda3/envs/opencv340/lib/python3.6/site-packages

    You can get the actual location from a python console with:

    >>> import sys
    >>> print(next(p for p in sys.path if 'site-packages' in p))
    

    Then (adapt accordingly to your case and cv2*.so actual name):

    cp /path/to/your/opencv/build/directory/lib/python3.6/site-packages/cv2.cpython-36m-x86_64-linux-gnu.so /home/yourself/anaconda3/envs/opencv340/lib/python3.6/site-packages/.

    And you should be able to import cv2 from a python console.

    I've just done so (ubuntu 16.04).

    0 讨论(0)
  • 2020-12-01 04:29

    If you are getting an error like the following:

        UnsatisfiableError: The following specifications were found to be in conflict:
                opencv 2.4.11* -> numpy 1.9* -> python 2.6* -> openssl 1.0.1*
                python 3.6*
                Use "conda info " to see the dependencies for each package.
    

    Just install python 3.5 and try again.

    conda install python=3.5
    conda install -c menpo opencv  # whichever
    conda install -c menpo opencv3 # you need
    
    0 讨论(0)
  • 2020-12-01 04:32

    None of the methods above worked for me. However, I found that this one liner works for me:

    conda install -c conda-forge opencv
    
    0 讨论(0)
提交回复
热议问题