cv2 import error on Jupyter notebook

前端 未结 9 875
误落风尘
误落风尘 2020-12-03 08:48

I\'m trying to import cv2 on Jupyter notebook but I get this error:

ImportError: No module named cv2

I am

9条回答
  •  悲&欢浪女
    2020-12-03 09:27

    To make this clear for those who are having the same issue:

    By default: Anaconda (jupyter notebook) has its own version of Python & packages once it has been installed on your PC.

    If you have Python x.x installed on your PC, and you installed OpenCV or -whatever packages- using the package manager of this python version, it does NOT mean your jupyter notebook will get access to these python packages you installed earlier. They are not living in the same folder.

    To illustrate this, open your windows CMD and write :

    `python` 
    

    then write:

    import os
    os.path
    

    you will get the path of your python. in my case (C:\Python35)

    Now open the Anaconda Prompt and write the same commands again:

    `python` 
    

    then write:

    import os
    os.path
    

    you will get the anaconda's python path. In my case (C:\Users\MY_NAME\Anaconda3).

    As you can see, there are two different paths of python, so make sure that your first step in diagnosing such error (No module named x) is to ask yourself whether you installed the package in the right place or not!

    N.B: within Anaconda itself you can create environments, each environment may have different packages installed in it, so you also have to make sure you're in the right environment and it is the active one.

提交回复
热议问题