ubuntu14.04中关于“No model named CV2”问题的彻底解决方法

       在ubuntu14.04中配置了不少的网络框架,发现出问题最多的还是opencv,要么就是版本不对,要么就是找不到cv2,网上也有不少的解决方法,但是都是比较杂,而且没有对其中的原因进行深入揭示,这篇博文完全是根据自己的理解和实践得到,不单纯的是一条语句解决问题,而是告诉大家以后遇到类似问题应该怎样找原因,进行修改。


 

一、查看版本

在ubuntu系统中,一般来说,有两个地方可以安装opencv,第一个在sudo下,第二个是在anaconda下,这两种环境下安装的opencv可能会引起冲突,如果一、查看版本你安装了anaconda,那么当你使用import cv2来导入opencv时,导入的是anaconda中安装的版本,这个时候出现的问题一般都是opencv的版本不对,下面给出查看opencv版本的方法:

(1)anaconda中:使用conda list调出安装的库,找到opencv那一行,查看其版本

(2)sudo下:在终端中输入 pkg-config opencv --modversion

 

你也可以通过sudo find / -iname "*opencv*"查看你opencv安装的位置,如果你在anaconda和sudo下都安装了opencv,那么你就可以发现得到的结果有两种目录。


二、安装opencv

1. anaconda中

conda install opencv

2. sudo下

sudo apt-get install python-opencv


三、修改版本

1. anaconda中

接下来先给出修改anaconda中opencv版本的方法:

conda uninstall opencv-2.4.9 (这里包含所有opencv的包,要全部列到后面)

注:如果是用pip安装的,那就使用 pip uninstall opencv-2.4.9

conda install opencv=3.0.0

2. sudo下

sudo下的版本修改其实就是安装新的版本,安装之前先卸载现有的版本:

在opencv安装目录下运行:

make uninstall
cd ..
sudo rm -r build
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
 

安装所需版本的opencv:(这里以3.0.0为例)

# step 1

# 安装依赖 (太多了,自己相应替换)

sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

 

sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip --fix-missing

 

 

# step 2

# 下载解包

wget https://github.com/Itseez/opencv/archive/3.0.0-alpha.zip

unzip opencv-3.0.0-alpha.zip

# step 3

# 编译

cd opencv-3.0.0-alpha

mkdir build

cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

# step 4

#安装

make

sudo make install

 

# step 5

# 安装完成,进行整理

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'

sudo ldconfig

sudo apt-get update

 


参考文献:

https://stackoverflow.com/questions/25726768/opencv-3-0-trouble-with-installation

https://blog.csdn.net/tengxing007/article/details/54380732

https://blog.csdn.net/zhenguo26/article/details/79627232

https://ptorch.com/news/37.html

https://blog.csdn.net/weixin_37251044/article/details/79274202

https://blog.csdn.net/fireflychh/article/details/73970244

 

 

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