Ubuntu18.04在python3.6下安装cv2

Ubuntu18.04在python3.6下安装cv2

  • 目录
    • A. 安装步骤
    • B. 测试

目录

记录下ubuntu18.04 在python3.6下安装cv2 模块过程。

A. 安装步骤

  1. 安装python3-pip:
sudo apt install python3-pip
  1. 遇到The directory '/home/work/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.问题时:
 sudo chown  root /home/work/.cache/pip/http
 sudo chown  root /home/work/.cache/pip
  1. 更新pip:
sudo pip3 install --upgrade pip

  1. 加速安装cv:
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python

B. 测试

如下,在import cv2 后未报错:

work@xxxxxxx:~$ python3
Error in sitecustomize; set PYTHONVERBOSE for traceback:
NameError: name 'reload' is not defined
Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.version)
<module 'cv2.version' from '/usr/local/lib/python3.6/dist-packages/cv2/version.py'>

你可能感兴趣的:(python笔记,opencv,python,ubuntu)