作者:mobiledu2502897351 | 来源:互联网 | 2023-10-11 20:05
Ubuntu下opencv源码编译安装后,却出现ImportError: No module named cv2问题。
解决办法:需要安装一些依赖。
apt-get换源加速:https://blog.csdn.net/qq_34717531/article/details/108103227
sudo apt-get install -y build-essential checkinstall cmake pkg-config yasm git gfortran
# 添加源,防止可能会出现的找不到所需安装的库的情况
sudo add-apt-repository -y "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get update
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y libjpeg8-dev libjasper-dev libpng12-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine2-dev libv4l-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgtk2.0-dev libtbb-dev libatlas-base-dev libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev libopencore-amrnb-dev libopencore-amrwb-dev x264 v4l-utils
问题:bash: add-apt-repository: command not found 解决:https://www.jianshu.com/p/986efb4025e8
如果需要python3支持则需要安装下面两个库:
sudo apt install python3-dev python3-numpy
可以选择安装一些可选的库:
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
然后再重新编译opencv(参考:https://blog.csdn.net/qq_34717531/article/details/107763872)
成功如下图: