0

I am using Ubuntu 14.04 and trying to install opencv 3.3.0. While I execute cmake to get the make files, it is not able to locate the Python interpreter, displaying the following message (though the cmake proceeds)

    -- Could NOT find PythonInterp: Found unsuitable version "2.7.6", 
       but required is at least "3.4" (found /usr/bin/python)
    -- Could NOT find PythonInterp: Found unsuitable version "2.7.6", 
       but required is at least "3.2" (found /usr/bin/python)

When I check /usr/bin/ , I could see python libraries/binaries present there (found in the image below)

enter image description here

I could also see the following versions of python

 python             python2.7-config   python3.4          python3.4m-
 config  python3.5m-config  python3m-config    
 python2            python2-config     python3.4-config   python3.5          
 python3-config     python-config      
 python2.7          python3            python3.4m         python3.5m         
 python3m           python-mkdebian  

How can I solve this? Due to this issue, I am not able to use cv2 in my python script, as it throws the following error

    ImportError: No module named 'cv2'
  • default version of python in 14.04 was 2; hence why you see 2.7. yes it installed python3 too which is why you see it, but it wasn't the default unless you made it so. refer https://askubuntu.com/questions/590027/how-to-set-python-3-as-default-interpreter-in-ubuntu-14-04 (16.04 had python3 as default) – guiverc Sep 30 '17 at 09:04
  • the method suggests to use python for scripting, which I already have in my bashrc file. Could not find any bash_aliases file. – Lakshmi Narayanan Sep 30 '17 at 09:10
  • and changing aliases doesn't work – Lakshmi Narayanan Sep 30 '17 at 09:10
  • try https://stackoverflow.com/questions/25215102/installing-opencv-for-python-on-ubuntu-getting-importerror-no-module-named-cv2 – guiverc Sep 30 '17 at 09:47
  • Why is your /usr/bin/python a 3.x python? What did you do? – muru Oct 01 '17 at 09:49

1 Answers1

-2
/usr/bin/python

is a symlink.

Try

ls -l /usr/bin/python

It's probably pointing to python2.7

You need to do (as root)

ln -f -s /usr/bin/python3.4 /usr/bin/python

This will delete the old symlink (because of the -f) and make a new one pointing to python3.4.

Unfortunately there are some incompatibilities between python version 2 and python version 3, so the above instructions may break some other applications. If you see that problem, you might try upgrading your version of cmake. cmake seems to look for a python interpreter using a list in the file

/usr/share/cmake-<version>/Modules/FindPythonInterp.cmake

If you have an older version of this file which contains a line like

set(_PYTHON3_VERSIONS 3.3 3.2 3.1 3.0)

you could try editing it to

set(_PYTHON3_VERSIONS 3.4 3.3 3.2 3.1 3.0)

I haven't tried this myself as I have a newer version of cmake, but it should be worth a try.