简体   繁体   English

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

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

I know that I could pip install opencv-python which 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.谢谢。

Via pip you 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==

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==

Easy and simple简单易行

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

Specific version * Final step * opencv-python==2.4.9具体版本 * 最后一步 * opencv-python==2.4.9

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!希望这可以帮助!

cv2 vs. "opencv3" cv2 与“opencv3”

To get a potential misunderstanding out of the way: The python OpenCV module is named and imported via import cv2 in all versions > 2.0, including > 3.0.为了消除潜在的误解:python OpenCV 模块在所有版本> 2.0(包括> 3.0)中通过import cv2命名和导入。 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.如果您想使用cv2 ,安装 OpenCV 版本 > 3 就可以了 - 除非您正在寻找与旧版本的特定兼容性或者是 2.4.x 版本的粉丝。 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.从 2.4.x 到 3.x 的切换是在 2015 年,就功能、速度和透明度而言,使用较新版本很有意义。 You can read here and here about major differences.您可以在此处此处阅读有关主要差异的信息。 2.4.x versions are still supported though, current release is 2.4.13.5. 2.4.x 版本仍然受支持,当前版本是 2.4.13.5。

Installing a specific version, eg 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 opencv nor conda install opencv=2.4.x provide (as explained by other answers here), you can always install from sources.也就是说:如果您想安装既不pip install opencv-python==2.4.Xsudo apt-get install opencv也不conda install opencv=2.4.x提供的特定版本(如此处其他答案所述),您可以始终从源安装。 In the sourceforge repository you can find all major versions for each operating system.sourceforge 存储库中,您可以找到每个操作系统的所有主要版本。 Although for unxeperienced users this might be scary, it is well explained in some tutorials.虽然对于没有经验的用户来说这可能会很可怕,但在一些教程中已经很好地解释了。 Eg here for 2.4.9 on Ubuntu 14.04.例如, 这里是 Ubuntu 14.04 上的 2.4.9。 Or here is the official Linux install doc for the latest release 2.4.13.5.或者这里是最新版本 2.4.13.5 的官方 Linux 安装文档。

In essence, the install process boils down to:本质上,安装过程归结为:

  1. install dependencies, refer to docs (eg here ) for required packages安装依赖项,请参阅文档(例如此处)以获取所需的包

  2. get sources from OpenCVs sourceforgeOpenCVs sourceforge获取源代码

    eg wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip例如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通过创建构建目录并运行 cmake 来解压缩源并准备构建

    mkdir build cd build cmake (... your build options ...)
  4. build in the created build directory with:在创建的构建目录中构建:

     make sudo make install

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

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

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

你可以试试这个

pip install opencv==2.4.9
python3.6 -m pip install opencv-python

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

python -m pip install opencv-python

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

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

Below Python packages are to be downloaded and installed to their default locations.下面的 Python 包将被下载并安装到它们的默认位置。

1.1. 1.1. Python-2.7.x. Python-2.7.x。

1.2. 1.2. Numpy.麻木。

1.3. 1.3. Matplotlib (Matplotlib is optional, but recommended since we use it a lot in our tutorials). Matplotlib(Matplotlib 是可选的,但推荐使用,因为我们在教程中经常使用它)。

Install all packages into their default locations.将所有软件包安装到它们的默认位置。 Python will be installed to C:/Python27/. Python 将安装到 C:/Python27/。

After installation, open Python IDLE.安装完成后,打开Python IDLE。 Enter import numpy and make sure Numpy is working fine.输入 import numpy 并确保 Numpy 工作正常。

Download latest OpenCV release from sourceforge site and double-click to extract it.从 sourceforge 站点下载最新的 OpenCV 版本并双击以提取它。

Goto opencv/build/python/2.7 folder.转到 opencv/build/python/2.7 文件夹。

Copy cv2.pyd to C:/Python27/lib/site-packeges.将 cv2.pyd 复制到 C:/Python27/lib/site-packeges。

Open Python IDLE and type following codes in Python terminal.打开 Python IDLE 并在 Python 终端中键入以下代码。

import cv2 print cv2.导入 cv2 打印 cv2。 version If the results are printed out without any errors, congratulations !!! version如果打印出来的结果没有任何错误,恭喜!!! You have installed OpenCV-Python successfully.您已成功安装 OpenCV-Python。

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html

The following command line pip install opencv-python==3.4.2.16 works properly.以下命令行pip install opencv-python==3.4.2.16正常工作。 Use one of the versions presented to you.使用提供给您的版本之一。 May be:或许:

3.1.0.5, 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, or 3.4.0.12, etc.

To make sure, you can see my screenshot.为了确保,你可以看到我的截图。 screenshot截图

First, get the correct opencv version extension which you want to install.首先,获取要安装的正确opencv 版本扩展。 If you want to install 3.4.9.20 then run pip install opencv-python==3.4.5.20 .如果你想安装 3.4.9.20 然后运行pip install opencv-python==3.4.5.20

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM