Python:如何使用特定版本 2.4.9 pip install opencv2?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44439443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:01:15  来源:igfitidea点击:

Python: How to pip install opencv2 with specific version 2.4.9?

pythonopencvpippackage

提问by matchifang

I know that I could pip install opencv-pythonwhich installs opencv3, but is there a separate command or name for opencv specific version such as 2.4.9?

我知道我可以pip install opencv-python安装 opencv3,但是对于 opencv 特定版本(例如 2.4.9)是否有单独的命令或名称?

If not, how can I specify which version to install?

如果没有,我如何指定要安装的版本?

Thanks.

谢谢。

回答by etemple1

Via pipyou can specify the package version to install using the following:

通过pip您可以使用以下命令指定要安装的软件包版本:

pip install opencv-python==2.4.9

However, that package does not seem to be available on pypi.

但是,该软件包似乎在pypi上不可用。

A little trick for checking available versions:

检查可用版本的小技巧:

pip install opencv-python==

pip install opencv-python==

Which returns:

返回:

Could not find a version that satisfies the requirement opencv-python== (from versions: 3.1.0.0, 3.1.0.1, 3.1.0.2, 3.1 .0.3, 3.1.0.5, 3.2.0.6, 3.2.0.7) No matching distribution found for opencv-python==

Could not find a version that satisfies the requirement opencv-python== (from versions: 3.1.0.0, 3.1.0.1, 3.1.0.2, 3.1 .0.3, 3.1.0.5, 3.2.0.6, 3.2.0.7) No matching distribution found for opencv-python==

回答by Abdul Sheikh

Easy and simple

简单易行

  • Prerequisites
    • pip install matplotlib
    • pip install numpy
  • Final step
    • pip install opencv-python
  • 先决条件
    • pip 安装 matplotlib
    • pip 安装 numpy
  • 最后一步
    • pip 安装 opencv-python

Specific version * Final step * opencv-python==2.4.9

具体版本 * 最后一步 * opencv-python==2.4.9

回答by Vinh Trieu

There's another easy way, you can type in terminal

还有另一种简单的方法,您可以在终端中输入

sudo apt-get install python-opencv

Install OpenCV-Python in Ubuntu

在 Ubuntu 中安装 OpenCV-Python

After installing it, you can use opencv version 2.4 in both c++ and python.

安装后,您可以在 c++ 和 python 中使用 opencv 2.4 版。

But I recommend you should use opencv 3.2.0 and opencv-contrib, it gives more features

但是我建议您应该使用 opencv 3.2.0 和 opencv-contrib,它提供了更多功能

Hope this can help!

希望这可以帮助!

回答by Honeybear

cv2 vs. "opencv3"

cv2 与“opencv3”

To get a potential misunderstanding out of the way: The python OpenCV module is named and imported via import cv2in all versions > 2.0, including > 3.0. If you want to work with cv2, installing OpenCV versions > 3 is fine - unless you're looking for specific compatibility with older versions or are a fan of the 2.4.x versions. The switch from 2.4.x to 3.x was in 2015 and in terms of features, speed and transparency, it makes much sense to use the newer versions. You can read hereand hereabout major differences. 2.4.x versions are still supported though, current releaseis 2.4.13.5.

为了消除潜在的误解:python OpenCV 模块import cv2在所有版本> 2.0(包括> 3.0 )中命名和导入。如果您想使用cv2,安装 OpenCV 版本 > 3 就可以了 - 除非您正在寻找与旧版本的特定兼容性或者是 2.4.x 版本的粉丝。从 2.4.x 到 3.x 的切换是在 2015 年,就功能、速度和透明度而言,使用较新版本很有意义。您可以在此处此处阅读有关主要差异的信息。2.4.x 版本仍然受支持,当前版本是 2.4.13.5。

Installing a specific version, e.g. OpenCV 2.4.9

安装特定版本,例如 OpenCV 2.4.9

That said: If you want to install a specific version that neither pip install opencv-python==2.4.X, sudo apt-get install opencvnor conda install opencv=2.4.xprovide (as explained by other answers here), you can always install from sources. In the sourceforge repositoryyou can find all major versions for each operating system. Although for unxeperienced users this might be scary, it is well explained in some tutorials. E.g. herefor 2.4.9 on Ubuntu 14.04. Or hereis the official Linux install doc for the latest release 2.4.13.5.

这就是说:如果你想安装一个特定版本既不pip install opencv-python==2.4.Xsudo apt-get install opencv也不conda install opencv=2.4.x提供(如这里其他的答案解释),你总是可以从源安装。在sourceforge 存储库中,您可以找到每个操作系统的所有主要版本。虽然对于没有经验的用户来说这可能会很可怕,但在一些教程中已经很好地解释了。例如,这里是 Ubuntu 14.04 上的 2.4.9。或者这里是最新版本 2.4.13.5 的官方 Linux 安装文档。

In essence, the install process boils down to:

本质上,安装过程归结为:

  1. install dependencies, refer to docs (e.g. here) for required packages

  2. get sources from OpenCVs sourceforge

    e.g. wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip

  3. unzip sources and prepare build by creating build directory and running cmake

    mkdir build
    cd build
    cmake (... your build options ...)
    
  4. build in the created build directory with:

    make
    sudo make install
    
  1. 安装依赖项,请参阅文档(例如此处)以获取所需的包

  2. OpenCVs sourceforge获取源代码

    例如 wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip

  3. 通过创建构建目录并运行 cmake 来解压缩源并准备构建

    mkdir build
    cd build
    cmake (... your build options ...)
    
  4. 在创建的构建目录中构建:

    make
    sudo make install
    

回答by Archie

You can also do it using Anaconda:

您也可以使用Anaconda来做到这一点:

conda install -c https://conda.binstar.org/menpo opencv=2.4.9

回答by kai06046

If you are using windows os, you can download your desired opencv unofficial windows binary from here, and type something like pip install opencv_python-2.4.13.2-cp27-cp27m-win_amd64.whlin the directory of binary file.

如果你使用的是 windows 操作系统,你可以从这里下载你想要的 opencv 非官方 windows 二进制文件,然后pip install opencv_python-2.4.13.2-cp27-cp27m-win_amd64.whl在二进制文件的目录中输入类似的内容。

回答by Rhythm sharma

you can try this

你可以试试这个

pip install opencv==2.4.9

回答by vishal

python3.6 -m pip install opencv-python

will install cv2 in linux in branch python3.6

将在 linux 中的分支 python3.6 中安装 cv2

回答by tech-gayan

python -m pip install opencv-python

which will install opencv based on your current python

它将根据您当前的python安装opencv

回答by GT_hash

If you're a Windows user, opencv can be installed using pip, like this:

如果您是 Windows 用户,可以使用 pip 安装 opencv,如下所示:

pip install opencv-python==<python version>

ex - pip install opencv-python==3.6

If you're a Linux user:

如果您是 Linux 用户:

sudo apt-get install python-opencv

At the same time, opencv can be installed using conda like this...

同时可以像这样使用conda安装opencv...

conda install -c https://conda.binstar.org/menpo opencv=3.6