Pycharm/Python OpenCV 和 CV2 安装错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37776228/
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
Pycharm/Python OpenCV and CV2 install error
提问by Sibi
I've been trying to install both OpenCV and cv2 from both Pycharm and from the terminal as suggested using:
我一直在尝试使用以下方法从 Pycharm 和终端安装 OpenCV 和 cv2:
pip install --user opencv
pip install --user cv2
but I'm getting the following error for them:
但我收到以下错误:
Collecting opencv
Could not find a version that satisfies the requirement opencv (from versions: )
No matching distribution found for opencv
and
和
Collecting cv2
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
How can I fix these and install the packages properly? I'm using python 3.4.
如何修复这些问题并正确安装软件包?我正在使用 python 3.4。
回答by Ryan Guest
You are getting those errors because opencv
and cv2
are not the python package names.
您收到这些错误是因为opencv
并且cv2
不是 python 包名称。
These are both included as part of the opencv-python
package available to install from pip.
这些都包含在opencv-python
可从 pip 安装的软件包中。
If you are using python 2 you can install with pip:
如果您使用的是 python 2,则可以使用 pip 安装:
pip install opencv-python
Or use the equivilent for python 3:
或者使用 python 3 的等效项:
pip3 install opencv-python
After running the appropriate pip command your package should be available to use from python.
运行适当的 pip 命令后,您的包应该可以从 python 使用。
回答by mdoc-2011
I ran into the same problem. One issue might be OpenCV is created for Python 2.7, not 3 (not all python 2.7 libraries will work in python 3 or greater). I also don't believe you can download OpenCV directly through PyCharm's package installer. I have found luck following the instructions: OpenCV Python. Specifically:
我遇到了同样的问题。一个问题可能是 OpenCV 是为 Python 2.7 而不是 3 创建的(并非所有的 Python 2.7 库都可以在 Python 3 或更高版本中运行)。我也不相信您可以通过 PyCharm 的软件包安装程序直接下载 OpenCV。我按照说明找到了运气:OpenCV Python。具体来说:
- Downloading and installing OpenCV from SourceForge
- Copying the cv2.pyd file from the download (opencv\build\python\2.7\x64) into Python's site-packages folder (something like: C:\Python27\Lib\site-packages)
- In PyCharm, open the python Console (Tools>Python Console) and type:
import cv2
, and assuming no errorsprint cv2.__version__
- 从SourceForge下载和安装 OpenCV
- 将下载的 cv2.pyd 文件(opencv\build\python\2.7\x64)复制到 Python 的 site-packages 文件夹(类似于:C:\Python27\Lib\site-packages)
- 在 PyCharm 中,打开 python 控制台(工具>Python 控制台)并输入:
import cv2
,并假设没有错误print cv2.__version__
Alternatively, I have had luck using this package opencv-python, which you can straightforwardly install using pip with pip install opencv-python
或者,我很幸运地使用了这个包opencv-python,您可以使用 pip 直接安装它pip install opencv-python
Good luck!
祝你好运!
回答by vishal
python3.6 -m pip install opencv-python
will install cv2 in python3.6 branch
将在 python3.6 分支中安装 cv2
回答by Sankha Rathnayake
This the correct command that you need to install opencv
这是安装 opencv 所需的正确命令
pip install opencv-python
if you get any error when you are trying to install the "opencv-python" package in pycharm, make sure that you have added your python path to 'System Variables' section of Environment variables in Windows. And also check whether you have configured a valid interpreter for your project
如果在 pycharm 中尝试安装“opencv-python”包时遇到任何错误,请确保已将 python 路径添加到Windows 环境变量的“系统变量”部分。并检查您是否为您的项目配置了有效的解释器
回答by Yogesh
Try this. I am using Jupyter notebook (OS: Ubuntu 16.04 LTS on Google Cloud Platform + on Windows). Executed following command in the Jupyter notebook to install opencv:
尝试这个。我正在使用 Jupyter notebook(操作系统:Ubuntu 16.04 LTS on Google Cloud Platform + on Windows)。在 Jupyter notebook 中执行以下命令来安装 opencv:
!pip install opencv-contrib-python #working on both Windows and Ubuntu
After successful installation you will get following message:
安装成功后,您将收到以下消息:
Successfully installed opencv-contrib-python-4.1.0.25
Now restart the kernel and try to import opencv as:
现在重新启动内核并尝试将 opencv 导入为:
import cv2
The same command can be used to installed opencv on Windows as well.
同样的命令也可用于在 Windows 上安装 opencv。
SOLUTION 2:try following commands to install opencv: For Ubuntu: Run following command from terminal:
解决方案 2:尝试使用以下命令安装 opencv:对于 Ubuntu:从终端运行以下命令:
sudo apt-get install libsm6 libxrender1 libfontconfig1
Restart Jupyter notebook kernel and execute following command:
重启 Jupyter notebook 内核并执行以下命令:
!pip install opencv-contrib-python
NOTE: You can run all the above commands from the terminal as well without using '!'.
注意:您也可以从终端运行上述所有命令,而无需使用“!”。
回答by Santhosh Dhaipule Chandrakanth
I rather use Virtualenv to install such packages rather than the entire system, saves time and effort rather than building from source.
我宁愿使用 Virtualenv 来安装这些包,而不是整个系统,这样可以节省时间和精力,而不是从源代码构建。
I use virtualenvwrapper
Windows user can download
Windows用户可以下载
pip install virtualenvwrapper-win
https://pypi.org/project/virtualenvwrapper-win/
https://pypi.org/project/virtualenvwrapper-win/
Linux follow
Linux关注
pip install opencv-python
If processing a video is required
如果需要处理视频
pip install opencv-contrib-python
If you do not need GUI in Opencv
如果您在 Opencv 中不需要 GUI
pip install opencv-contrib-python-headless
回答by Judit
here is a tutorialthat worked for me without any problem.
Copied from the site above the important part:
从上面的网站复制的重要部分:
Download the OpenCV version corresponding to your Python installation from here. In my case, I've used opencv_python-3.1.0-cp35-cp35m-win32.whl.
Now, open a cmd window like before. You can open this directly in your Downloads folder if you SHIFT and right click inside it. The idea is to open a cmd window where you've downloaded the above [...] file. Use the [...] command to install [...] OpenCV:
1 pip install "opencv_python-3.1.0-cp35-cp35m-win32.whl"
从此处下载与您的 Python 安装相对应的 OpenCV 版本。就我而言,我使用了 opencv_python-3.1.0-cp35-cp35m-win32.whl。
现在,像以前一样打开一个 cmd 窗口。如果您按住 SHIFT 并右键单击它,则可以直接在“下载”文件夹中打开它。这个想法是打开一个 cmd 窗口,您已经在其中下载了上述 [...] 文件。使用 [...] 命令安装 [...] OpenCV:
1 pip install "opencv_python-3.1.0-cp35-cp35m-win32.whl"
Additional note: don't forget to change the name of the downloaded file in the command you use. Apparently by installing opencv, you'll have access to cv2 too.
附加说明:不要忘记在您使用的命令中更改下载文件的名称。显然,通过安装 opencv,您也可以访问 cv2。
回答by daniel
Installing opencv is not that direct. You need to pre-install some packages first.
安装 opencv 不是那么直接。您需要先预安装一些软件包。
I would not recommend the unofficial package opencv-python. Does not work properly in macos and ubuntu (see this post). No idea about windows.
我不会推荐非官方软件包 opencv-python。在 macos 和 ubuntu 中无法正常工作(请参阅此帖子)。不知道窗户。
There are many webs explaining how to install opencv and all required packages. For example this one.
有很多网站解释了如何安装 opencv 和所有必需的包。比如这个。
The problem of trying to install opencv several times is that you need to uninstall completely before attempting again, or you might end having many errors.
多次尝试安装opencv的问题是需要完全卸载才能再次尝试,否则可能会出现很多错误。
回答by Yunus Emre Demirba?
you must install opencv-python
pip/pip3 install opencv-python
if you try import opencv-python
, receive error.
Fix this error, use the import cv2
pip/pip3 install opencv-python
如果你尝试import opencv-python
,你必须安装 opencv-python
,收到错误。修复这个错误,使用import cv2
回答by plotseeker
How about try some different mirrors? If you are in China, I highly recommend you try:
试试不同的镜子怎么样?如果您在中国,我强烈建议您尝试:
sudo pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ opencv-contrib-python
If not, just replace the url address to some other mirrors you like! Good luck.
如果没有,只需将url地址替换为您喜欢的其他镜像!祝你好运。