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
Import OpenCV on jupyter 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-
之后,当我尝试在命令提示符下导入 cv2 时,它已成功导入-
When I tried importing it on jupyter notebook, this error popped up-
当我尝试在 jupyter notebook 上导入它时,出现了这个错误——
This is the python version I'm using-
This is pip list and as I've highlighted, opencv-contrib-python version 3.4.3.18 is installed-
这是 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”