Python 在 jupyter notebook 上导入 OpenCV

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52832991/
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-19 20:12:23  来源:igfitidea点击:

Import OpenCV on jupyter notebook

pythonopencvpipjupyter-notebook

提问by guptasaanika

I tried installing OpenCV on Windows 10 using pip. I used this command- pip install opencv-contrib-python

我尝试使用 pip 在 Windows 10 上安装 OpenCV。我用了这个命令- pip install opencv-contrib-python

After that when I tried importing cv2 on command prompt, it was successfully imported- Importing cv2 successfully through command prompt

之后,当我尝试在命令提示符下导入 cv2 时,它已成功导入- 通过命令提示符成功导入 cv2

When I tried importing it on jupyter notebook, this error popped up- Error when importing cv2 on jupyter notebook

当我尝试在 jupyter notebook 上导入它时,出现了这个错误—— 在 jupyter notebook 上导入 cv2 时出错

This is the python version I'm using- Python version that I am using

这是我正在使用的python版本- 我正在使用的 Python 版本

This is pip list and as I've highlighted, opencv-contrib-python version 3.4.3.18 is installed- pip list

这是 pip 列表,正如我所强调的,安装了 opencv-contrib-python 版本 3.4.3.18- 点子列表

Then why can't I import OpenCV on jupyter notebook, like tensorflow or numpy are also in pip list and I'm able to import them both through command prompt and also on jupyter notebook.

那么为什么我不能在 jupyter notebook 上导入 OpenCV,比如 tensorflow 或 numpy 也在 pip 列表中,我可以通过命令提示符和 jupyter notebook 导入它们。

Please help. Thanks a lot.

请帮忙。非常感谢。

回答by Michael Muttiah

You have installed openCV in Python running on your Terminal, not into the working environment which Jupyter Notebooks is running from.

您已经在终端上运行的 Python 中安装了 openCV,而不是安装到运行 Jupyter Notebooks 的工作环境中。

Whilst in Terminal write:

在终端写:

py -m pip install opencv-python

When you use pip list

当你使用 pip list

You should see opencv-python 3.4.3.18

你应该看到 opencv-python 3.4.3.18

More information here.

更多信息在这里

回答by amravi shah

You should open the anaconda prompt and then type:

您应该打开 anaconda 提示符,然后键入:

conda install opencv 

It should work.

它应该工作。

回答by Sergey

It seems like you run jupyter not from conda environment, that has opencv module installed. try to do this: conda activate <your environment>

看起来你不是从 conda 环境运行 jupyter,它安装了 opencv 模块。尝试这样做: conda activate <your environment>

conda install jupyter
jupyter notebook

after that try to "import cv2"

之后尝试“导入 cv2”

回答by Om Sao

In the Anaconda Navigator. Launch conda console as below. enter image description here

在 Anaconda 导航器中。如下启动 conda 控制台。 在此处输入图片说明

In the console: run conda install opencventer image description here

在控制台中:运行 conda install opencv在此处输入图片说明