Python 如何使用 pip 安装 opencv?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51853018/
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
How do I install opencv using pip?
提问by Ian Boag
I need to install cv2
for a script that has been written for me. I tried pip install cv2
and pip install open_cv
and got the same problem - a warning message from dist.py
and complains about zlib
being not found. No cv2 installed. I also tried pyopenvc
and pip install opencv-python
.
我需要安装cv2
一个为我编写的脚本。我尝试 pip install cv2
并pip install open_cv
遇到了同样的问题 - 来自dist.py
并抱怨zlib
未找到的警告消息。没有安装cv2。我也试过pyopenvc
和pip install opencv-python
。
So, I went to the opencv site and downloaded the relevant exe. Ran it - generated a heap of subdirectories and a make file and stuff.
所以,我去opencv网站下载了相关的exe。运行它 - 生成了一堆子目录和一个 make 文件和东西。
What do I do now?
现在我该怎么做?
回答by Kuldeep Thakre
Install opencv-python
(which is an unofficialpre-built OpenCV package for Python) by issuing the following command:
通过发出以下命令安装opencv-python
(这是一个非官方的 Python 预构建 OpenCV 包):
pip install opencv-python
Make sure your command prompt has sudo elevated permissions.
确保您的命令提示符具有 sudo 提升的权限。
回答by HamzaMushtaq
run the following command by creating a virtual enviroment using python 3 and run
通过使用python 3创建虚拟环境来运行以下命令并运行
pip3 install opencv-python
to check it has installed correctly run
检查它是否已正确安装运行
python3 -c "import cv2"
回答by abhi krishnan
As of OpenCV 2.2.0, the package name for the Python bindings is "cv".The old bindings named "opencv" are not maintained any longer. You might have to adjust your code. See http://opencv.willowgarage.com/wiki/PythonInterface.
从 OpenCV 2.2.0 开始,Python 绑定的包名称为“cv”。不再维护名为“opencv”的旧绑定。您可能需要调整您的代码。请参阅http://opencv.willowgarage.com/wiki/PythonInterface。
The official OpenCV installer does not install the Python bindings into your Python directory. There should be a Python2.7 directory inside your OpenCV 2.2.0 installation directory. Copy the whole Lib folder from OpenCV\Python2.7\ to C:\Python27\ and make sure your OpenCV\bin directory is in the Windows DLL search path.
官方 OpenCV 安装程序不会将 Python 绑定安装到您的 Python 目录中。您的 OpenCV 2.2.0 安装目录中应该有一个 Python2.7 目录。将整个 Lib 文件夹从 OpenCV\Python2.7\ 复制到 C:\Python27\ 并确保您的 OpenCV\bin 目录在 Windows DLL 搜索路径中。
Alternatively use the opencv-python installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.
或者使用http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv 上的 opencv-python 安装程序。
Or Simply install
或者简单地安装
sudo pip3 install opencv-python #for python3
sudo pip install opencv-python #for python2
回答by HamzaMushtaq
Make a virtual enviroment using python3
使用python3制作虚拟环境
virtualenv env_name --python="python3"
and run the following command
并运行以下命令
pip3 install opencv-python
to check it has installed correctly run
检查它是否已正确安装运行
python3 -c "import cv2"
回答by Kamble Tanaji
Everybody struggles initially while installing opencv. Opencv requires lot of dependencies in back-end. The best way to start with opencv is, install it in virtual environment. I suggest you to first install python anaconda distribution and create virtual environment using it. Then inside virtual environment using conda install command you can easily install opencv. I feel this is the most safe and easy approach to install opencv. The following command work for me, you can try the same.
在安装 opencv 时,每个人最初都在挣扎。Opencv 在后端需要很多依赖项。开始使用 opencv 的最佳方法是,将其安装在虚拟环境中。我建议您首先安装 python anaconda 发行版并使用它创建虚拟环境。然后在虚拟环境中使用 conda install 命令可以轻松安装 opencv。我觉得这是安装opencv最安全、最简单的方法。以下命令对我有用,您可以尝试相同的方法。
conda install -c menpo opencv3
回答by user3731622
As of 10/22/2019, I think the best answer is simply
截至 2019 年 10 月 22 日,我认为最好的答案很简单
conda install opencv
It appears opencv
is now in the main Anaconda
channel.
它opencv
现在出现在主Anaconda
频道中。
To see which packages (including opencv
) are in the main Anaconda
channel go to Anaconda Package Listsand follow the link corresponding to your python version and os version.
要查看opencv
主Anaconda
频道中有哪些包(包括),请转到Anaconda 包列表并按照与您的 python 版本和 os 版本对应的链接进行操作。
回答by Azhar hussain
Simply use this for the so far latest version 4.1.0.
只需将它用于迄今为止的最新版本 4.1.0。
pip install opencv-contrib-python==4.1.0.25
For default version use this:
对于默认版本,请使用:
pip install opencv-contrib-python
For quick installation: https://youtu.be/iZKVFwez260
快速安装:https: //youtu.be/iZKVFwez260
回答by user3136136
Open anaconda command prompt and type in below command.
conda install -c conda-forge opencv
Once the 'Solving environment' is done. It will ask to download dependencies. Type 'y'.
- It will install all the dependencies and then you are ready to code.
打开 anaconda 命令提示符并输入以下命令。
conda install -c conda-forge opencv
一旦“解决环境”完成。它将要求下载依赖项。输入'y'。
- 它将安装所有依赖项,然后您就可以编写代码了。
回答by TMan
I recommend this for Python 3: Please install it this way with pip
我为 Python 3 推荐这个:请使用 pip 以这种方式安装它
pip3 install opencv-python
This will download and install the latest version of OpenCV.
这将下载并安装最新版本的 OpenCV。
回答by Md Abul Kashem
- Open terminal
- Run the following command
pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org opencv-python
. - Hope it will work.
- 打开终端
- 运行以下命令
pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org opencv-python
。 - 希望它会起作用。