在Ubuntu 15.04中使用Python3安装opencv-python

时间:2017-09-14 06:35:06

标签: python python-3.x opencv ubuntu

我希望通过Ubuntu 15.04机器中的命令安装opencv-python

pip3 install opencv-python

但是一旦我运行此命令,我就会收到以下错误:

Downloading/unpacking opencv-python
Could not find any downloads that satisfy the requirement opencv-python
Cleaning up...
No distributions at all found for opencv-python
Storing debug log for failure in /home/Nadeem/.pip/pip.log

非常感谢任何帮助。 谢谢!

2 个答案:

答案 0 :(得分:4)

您可以从源安装opencv 请按照this链接进行操作 或者您可能需要使用以下命令升级您的pip3

pip3 install --upgrade pip

修改

为了完整性(如果链接断开)我在这里列出了在Ubuntu上从源代码编译和安装OpenCV的步骤(使用python 3在Ubuntu 14.04 LTS上测试过)。

步骤1更新软件包

sudo apt-get update
sudo apt-get upgrade

步骤2安装依赖项

sudo apt-get install build-essential cmake git pkg-config # Developer tools required to compile opencv
sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev # Libraries required to read various image format from disk
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev # Libraries required to read various video formats
sudo apt-get install libgtk2.0-dev # Required by opencv for GUI features
sudo apt-get install libatlas-base-dev gfortran # Packages used by opencv to optimize various functions.

pip3 install --upgrade pip  

步骤3设置虚拟环境(使用conda)

conda create -n opencv-exmaple-env python=3.6

source activate opencv-exmaple-env # Activate the envirnoment 

步骤4安装编译opencv所需的包

sudo apt-get install python3.6-dev # If the python version is not 3.6 then make changes to this command accordingly. 
pip install numpy # This should be done after the environment in Step 3 is activated

步骤5:使用Python 3.4+绑定构建和安装OpenCV 3.0

5.1克隆opencv源

cd ~
mkdir opencv-source
cd opencv-source
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 3.3.0 # Branch you want to compile from 

5.2 Clone Opencv Contrib rep

包含exptra功能,如标准关键点检测器和局部不变量描述符(如SIFT,SURF等)


cd ~
mkdir opencv-contrib
cd opencv-contrib
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib
git checkout 3.3.0 # The version you want to compile

5.3编译,构建和安装

cd ~/opencv-source/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv-contrib/opencv_contrib/modules \
    -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig

5.4将已安装的opencv目标文件链接到python站点包

ln -s /usr/local/lib/python3.6/site-packages/cv2.so /path-to-python-sitepackages-of-the-environment/cv2.so

6验证安装

import cv2

如果上面的代码运行没有错误,那么opencv已成功安装。

答案 1 :(得分:2)

首先使用sudo升级点数。

arsho:~/workspace $ sudo pip3 install --upgrade pip                                                                                       
Successfully installed pip

现在使用opencv-python命令再次安装sudo

arsho:~/workspace $ sudo pip3 install opencv-python
Successfully installed numpy-1.13.1 opencv-python-3.3.0.10

最后使用pip检查opencv-python版本和位置信息。

arsho:~/workspace $ pip3 show opencv-python
---
Name: opencv-python
Version: 3.3.0.10
Location: /usr/local/lib/python3.4/dist-packages
Requires: numpy

我使用https://c9.io/中的Ubuntu 14.04.5 LTS对此进行了测试。