Ubuntu18
$ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 9 Apr 16 2018 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root 9 Apr 16 2018 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3670448 Nov 12 22:31 /usr/bin/python2.7
lrwxrwxrwx 1 root root 33 Nov 12 22:31 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 16 Apr 16 2018 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root 9 Oct 25 19:11 /usr/bin/python3 -> python3.6
-rwxr-xr-x 2 root root 4522328 Oct 22 19:32 /usr/bin/python3.6
lrwxrwxrwx 1 root root 33 Oct 22 19:32 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
-rwxr-xr-x 2 root root 4522328 Oct 22 19:32 /usr/bin/python3.6m
lrwxrwxrwx 1 root root 34 Oct 22 19:32 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
lrwxrwxrwx 1 root root 16 Oct 25 19:11 /usr/bin/python3-config -> python3.6-config
lrwxrwxrwx 1 root root 10 Oct 25 19:11 /usr/bin/python3m -> python3.6m
lrwxrwxrwx 1 root root 17 Oct 25 19:11 /usr/bin/python3m-config -> python3.6m-config
lrwxrwxrwx 1 root root 16 Apr 16 2018 /usr/bin/python-config -> python2.7-config
lake@lake-Latitude-5491:~$ sudo apt-get install libopencv-dev
....................................
....................................
.................................
Setting up libopencv-highgui-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-features2d3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-superres-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-features2d-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-calib3d3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-stitching3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-calib3d-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-objdetect-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-videostab3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-stitching-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-contrib3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-videostab-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-contrib-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv3.2-jni (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv3.2-java (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-dev (3.2.0+dfsg-4ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
lake@lake-Latitude-5491:~$ sudo apt-get install python-opencv
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
python-numpy
Suggested packages:
gfortran python-nose python-numpy-dbg python-numpy-doc
The following NEW packages will be installed:
python-numpy python-opencv
0 upgraded, 2 newly installed, 0 to remove and 325 not upgraded.
Need to get 2,472 kB of archives.
After this operation, 13.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 python-numpy amd64 1:1.13.3-2ubuntu1 [1,938 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 python-opencv amd64 3.2.0+dfsg-4ubuntu0.1 [535 kB]
Fetched 2,472 kB in 7s (371 kB/s)
Selecting previously unselected package python-numpy.
(Reading database ... 155024 files and directories currently installed.)
Preparing to unpack .../python-numpy_1%3a1.13.3-2ubuntu1_amd64.deb ...
Unpacking python-numpy (1:1.13.3-2ubuntu1) ...
Selecting previously unselected package python-opencv.
Preparing to unpack .../python-opencv_3.2.0+dfsg-4ubuntu0.1_amd64.deb ...
Unpacking python-opencv (3.2.0+dfsg-4ubuntu0.1) ...
Setting up python-numpy (1:1.13.3-2ubuntu1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up python-opencv (3.2.0+dfsg-4ubuntu0.1) ...
lake@lake-Latitude-5491:~/opencv3.2-sample-ubuntu18/image$ sudo apt-get install python-opencv
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-opencv is already the newest version (3.2.0+dfsg-4ubuntu0.1).
0 upgraded, 0 newly installed, 0 to remove and 325 not upgraded.
lake@lake-Latitude-5491:~/opencv3.2-sample-ubuntu18/image$ python2.7
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
3.2.0
>>>
### #Example
lake@lake-Latitude-5491:~/opencv3.2-sample-ubuntu18/image$ python2.7 ./image.py
lake@lake-Latitude-5491:~/opencv3.2-sample-ubuntu18/image$ cat ./image.py
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import cv2
img = cv2.imread('../lena.jpg')
cv2.namedWindow('Image')
cv2.imshow('Image', img)
cv2.waitKey(0)