Ubuntu18.04在python3.6下安装cv2

本文详细记录了在Ubuntu18.04系统中,使用Python3.6环境安装OpenCV库的过程。首先通过sudo apt install python3-pip安装pip,然后解决权限问题,接着升级pip到最新版,最后通过清华源加速安装opencv-python。安装完成后,通过Python3交互模式导入cv2模块并打印版本号验证安装成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ubuntu18.04在python3.6下安装cv2

目录

记录下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'>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值